Hello @vnyprsd
The checkbox control includes the attribute: “Merge ticked up options (sum or concatenation) or their values are returned as an array.”
When the attribute is ticked, the field’s value would be the sum or concatenation of the ticked choices’ values. If the attribute is unticked, the field’s value would be an array with the values of ticked choices.
I’ll try to describe the process with a hypothetical example:
Assuming the feldname1 is a checkbox field with three choices:
First choice with text “A” and value 1
Second choice with text “B” and value 2
Third choice with text “C” and value 3
If the attribute in the field’s settings is ticked, and the user ticks the first and third choices, the field’s value in the equation would be the number 4.
If the attribute is unticked, the field’s value would be the array: [1,3]
Best regards.
Hi! How to get value from checkbox in array? fieldname1[1](for example)?
Hello @smopuim
Please use the field’s name with the |r modifier, like fieldname1|r
The |r modifier gives you access to the field’s values in the raw mode without preprocessing. The result will be an array with the values of ticked checkboxes.
Best regards.
Understood thanks! And how to get not the array itself, but the desired element from the array?
Hello @smopuim
The field’s value is an array with the values of the ticked choices. So you can access its items through the indexes. For example, assuming your checkbox field is the fieldname1, and you want to get the higher value of the ticked choices. The equation can be implemented as follows:
(function(){
var values = fieldname1|r, result = values[0];
for(var i=1; i<values.length;i++) result = MAX(result, values[i]);
return result;
})()
The previous equation can be implemented as follows:
MAX(fieldname1|r)
But I implemented the first version with a for loop to teach you to access the array items.
Best regards.