Solved

Radio Button List (get count)

  • 25 July 2017
  • 6 replies
  • 32 views

Badge +8

Hi All

 

I have a Radio Button List control on a smartform which is being populated by a SmartObject

I'd like to get a count of the number of items populated in the control when it's populated 

 

Have tried using a the list count function and others but cant find a way to achieve it.

 

Anybody have a solution?

 

thanks
Paul

icon

Best answer by Albarghouthy 25 July 2017, 13:18

View original

6 replies

Userlevel 5
Badge +16

Hi Paul,


 


Maybe this script can help, transfer it to a data label after populating the radio button list


 


 


<script type="text/javascript">
var count = $(".stack-container label").length;
$("[name='dlCount']").SFCLabel('option', 'text', count);
</script>

 


Check 'Literal' property for the data label 


Add another data label to set the count value, in my script I am setting the value to data label called dlCount.


 


You can also write stored procedure to return the count if your data source is SQL.


If you have more than one radio button list control on your form/view, the above script will not return the correct count


 


you can use this for specific Radio button list control:


 


var count = $( "div[id$='MultiSelectPanel']").eq(0).find('label').length;

** eq(0) is used to select element at index n.


 


hope that helps


 


 

Badge +8

Hi Mustafa

This nearly works for me - but I found one small issue
I'm filtering the radio button list data based on a text value I pass to the control


this works OK:-
1. Input string into text box
2. Return matched results into radio button list
3. transfer your script to data label and get count

However if I enter a new value into the text box and rerun script the previous count is retained even if the number of results are different
Seems the initial value is always kept

Is there someway I can reset when I run again?

 

Paul

Userlevel 5
Badge +16

Hi Paul,


 


Clear the data label that contains the script after transferring it.


 


So you will need two transfer actions


 


1- transfer script to data label.


2- clear data label.

Badge +8

Great - that works - thanks again

Badge +7

I have been trying to do this but I must be missing something. I am using a chocie control with check boxes if that makes any difference. Here is what I did.

 

I create a rule on the choice list called 'What BU or Groups will use Choice' , on changed

Used a data transfer to copy this script into a data label control called "bucountData Label1".

 

<script type="text/javascript">
 var count = $( "div[id$='What BU or Groups will use Choice']").eq(0).find('label').length;
  $("[name='ScoreData LabelGroups']").SFCLabel('option', 'text', count);
</script>

 

All I get in 'ScoreData LabelGroups' is a zero.

 

What did I do wrong? Any help appreciated

 

 

Userlevel 5
Badge +16

Hi 


 


Modify the selector to name instead of id:


 


<script type="text/javascript">
var count = $( "div[name$='What BU or Groups will use Choice']").eq(0).find('label').length;
$("[name='ScoreData LabelGroups']").SFCLabel('option', 'text', count);
</script>

hope that helps

Reply