Need checkboxField to deselect options when certain options are selected.

I have an ask to make a checkbox field have the following logic. 

Checkbox has four items. If option ITEM 1 is selected then selection of ITEM 2, ITEM 3, ITEM 4 should be deselected automatically.

If options ITEM 2, ITEM 3, ITEM 4 are selected then option ITEM 1 should be deselected automatically.

Below code tracks the current values for the checkbox field in local!setA, previous values in local!setB, and the difference between the two sets which indicates what object the user just clicked in local!setDIFF.

The issue we are encountering is that when the deselection logic is triggered, I can see local!setA's value meets the requirement but the checkboxField UI doesn't. It still shows the options as selected when they have been removed from local!setA. User has to make another mouse click action like clicking around the page then the UI reflects the local!setA values.

Has anyone experienced a similar issue with checkboxField and were able to have the checkbox options refresh to match the local value?

a!localVariables(
  local!setA:null,
  local!setB:null,
  local!setDIFF:null,
  a!checkboxField(
    align:"LEFT",
    labelPosition:"COLLAPSED",
    choiceLayout:"COMPACT",
    choiceLabels:{"ITEM 1","ITEM 2","ITEM 3","ITEM 4"},
    choiceValues:{"ITEM 1","ITEM 2","ITEM 3","ITEM 4"},
    value: local!setA,
    saveInto: {
      a!save(local!setB,local!setA),
      a!save(local!setDIFF,difference(save!value,local!setB)),
      a!save(local!setA,
      if(
        contains(local!setDIFF,"ITEM 1"),
        {"ITEM 1"},
        difference(save!value,{"ITEM 1"}),
      )
      )
    }
  )
)

  Discussion posts and replies are publicly visible

Parents
  • Due to this behavior of not updating until an additional click is made outside of the form, I'll typically implement a setup with multiple checkboxes, one for each option.  In this scenario, the updates are persisted as soon as you choose a value.  Try the example below.  This uses an interim local variable that always has the same length as the options, then the output variable rejects nulls for your final list.

    a!localVariables(
      local!options: {"ITEM 1","ITEM 2","ITEM 3","ITEM 4"},
      local!selected: repeat(count(local!options),null),
      local!selected_output: reject(fn!isnull,{local!selected}),
      {
        a!forEach(
          items: local!options,
          expression: a!checkboxField(
            choiceLabels: local!options[fv!index],
            choiceValues: local!options[fv!index],
            value: local!selected[fv!index],
            saveInto: {
              local!selected[fv!index],
              if(
                and(fv!isFirst,not(isnull(local!selected[1]))), /* Populating Item 1 */
                a!save(local!selected,{local!options[1],repeat(count(local!options)-1,null)}),
                if(
                  and(not(fv!isFirst),not(isnull(local!selected[fv!index]))), /* Populating Items 2-4 */
                  a!save(local!selected,{null,index(local!selected,2+enumerate(count(local!options)-1))}),
                  {}
                )
              )
            }
          )
        ),
        a!textField(
          label: "Selected (output): ", 
          value: local!selected_output, 
          readOnly: true
        )
      }
    )

Reply
  • Due to this behavior of not updating until an additional click is made outside of the form, I'll typically implement a setup with multiple checkboxes, one for each option.  In this scenario, the updates are persisted as soon as you choose a value.  Try the example below.  This uses an interim local variable that always has the same length as the options, then the output variable rejects nulls for your final list.

    a!localVariables(
      local!options: {"ITEM 1","ITEM 2","ITEM 3","ITEM 4"},
      local!selected: repeat(count(local!options),null),
      local!selected_output: reject(fn!isnull,{local!selected}),
      {
        a!forEach(
          items: local!options,
          expression: a!checkboxField(
            choiceLabels: local!options[fv!index],
            choiceValues: local!options[fv!index],
            value: local!selected[fv!index],
            saveInto: {
              local!selected[fv!index],
              if(
                and(fv!isFirst,not(isnull(local!selected[1]))), /* Populating Item 1 */
                a!save(local!selected,{local!options[1],repeat(count(local!options)-1,null)}),
                if(
                  and(not(fv!isFirst),not(isnull(local!selected[fv!index]))), /* Populating Items 2-4 */
                  a!save(local!selected,{null,index(local!selected,2+enumerate(count(local!options)-1))}),
                  {}
                )
              )
            }
          )
        ),
        a!textField(
          label: "Selected (output): ", 
          value: local!selected_output, 
          readOnly: true
        )
      }
    )

Children