I'm trying to implement a visibility rule that uses the 'number of selected items' in a data driven checkbox group (data.accounts), as follows:
If only 1 item is selected return false
If more than 1 item is selected return true
I've tried to use 'data.accounts.length', but when I write that to the console it displays 'undefined'
Is there a way to count the number of selected items?
thanks for the suggestion.
This KB article (Selected Option in data driven check box) made a similar suggestion and showed an example of the calculation to get the number of checked boxes.
However, when I use the 'data.accounts.length' value in the calculation it returns undefined.
So, I think I'm on the right track, but can't seem to get the code to return the actual number of checked boxes.
Apologies, I missed the context, the undefined error.
I had a similar issue where I was trying to put a visibly rule on my data field, but not getting any results. I changed my data type to be a radio button and I've hidden those fields using the Maestro layout manager. This worked for me.
According to this article "You cannot attach a visibility rule directly to a data field " as we were trying to do.
Clearing data immediately - what happens to hidden data fields?
I suspect whats happening is .length isn't being populated because of the data field type and the controls associated to that field.
Previously I've used a data field to drive the visibility independently of the dynamic data code, so maybe it could help in your instance?
Pseudo for Maestro block
Wrap all checkboxes in a block
Create data field in Maestro and put that field in the same wrapped block
Return the datafield value (how many boxes are selected)
Put the visibility rule on the data field
Pseudo for visibility
if datafield > 3 then display the three items.
if datafield < 4 then dont
Let me know if this helps at all?