1
0
-1

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

Mark

    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      Hi Fred,

      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.

      Thanks

      Mark

      1. Fred Storbeck

        Hi Mark,

        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. 

        Cheers,

        Fred


      CommentAdd your comment...
    2.  
      1
      0
      -1

      Hi Mark,

      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? 

      I would: 


      Pseudo for Maestro block

      Wrap all checkboxes in a block

      Create data field in Maestro and put that field in the same wrapped block

      Add a calculation javascript rule on the new data field to return the number of selected checkboxes 

      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? 

      Cheers,

      Fred


        CommentAdd your comment...