How to select all the option in the multipledropdown field by default and also provide "select all" option in dropdown

Certified Associate Developer

Hi All,

i want to know , how to configure the below logic

BY default all the option should be selected. and also in dropdown i can have the option to deselect all /select all along with all the options.

Please help me how i can go about this

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Associate Developer
    in reply to Anitha Dharmalingam

    Well in that case try this code ,this can be a workaround the intended functionality

    a!localVariables(
      local!allOptions: {
        1, 2, 3, 4
      },
    
      local!selectedOptions: local!allOptions, /* Default: all selected */
    
      local!selectAll: true, /* Controls checkbox */
    
      {
        a!checkboxField(
          label: "Select All",
          choiceLabels: {"All"},
          choiceValues: {true},
          value: if(count(local!selectedOptions) = count(local!allOptions), {true}, {}),
          saveInto: {
            a!save(
              local!selectedOptions,
              if(
                or(a!isNullOrEmpty(save!value) , length(save!value) = 0),
                {}, /* Deselect all */
                local!allOptions /* Select all */
              )
            )
          }
        ),
    
        a!multipleDropdownField(
          label: "Options",
          choiceLabels: {"Option 1", "Option 2", "Option 3", "Option 4"},
          choiceValues: local!allOptions,
          value: local!selectedOptions,
          saveInto: {
            a!save(local!selectedOptions, save!value)
          }
        )
      }
    )

  • 0
    Certified Associate Developer
    in reply to Megha Ramnani

    Hi Meha... it works 70% of the expected outcome. am facing one trouble here. for example in multiple dropdown i have options like A B C D. as per above code by default all four options got selected and select all check box also got selected.

    1. user deselected some options like A C and check box got deselected. and suddenly if user want to select all the option when i click on all check box am getting error. because checkbox has one value only. can you please help me out here. i tried many things but i couldnt

  • 0
    Certified Lead Developer
    in reply to Anitha Dharmalingam

       I tried Megha's code, and it looks good to me based on your needs. Could you share the code you're using that's causing the error?

  • +1
    Certified Associate Developer
    in reply to Anitha Dharmalingam

    Hi Anitha,

    The overall approach in above code works as expected just as you explained not sure what is the issue you are facing! I just made a few small tweaks to improve stability.

    Here’s the updated version:

    a!localVariables(
      local!allOptions: {1, 2, 3, 4},
      local!selectedOptions: {1, 2, 3, 4},
      local!selectAll: true,
    
      {
        /* Checkbox Field for Select All / Deselect All */
        a!checkboxField(
          label: if(local!selectAll, "Deselect All", "Select All"),
          choiceLabels: {""},
          choiceValues: {true},
          value: if(local!selectAll, {true}, {}),
          saveInto: {
            a!save(
              local!selectedOptions,
              if(
                a!isNullOrEmpty(save!value),
                {}, /* Deselect all */
                local!allOptions /* Select all */
              )
            ),
            a!save(local!selectAll, not(a!isNullOrEmpty(save!value)))
          }
        ),
    
        /* Multiple Dropdown Field */
        a!multipleDropdownField(
          label: "Options",
          choiceLabels: {"A", "B", "C", "D"},
          choiceValues: local!allOptions,
          value: local!selectedOptions,
          saveInto: {
            a!save(local!selectedOptions, save!value),
            a!save(
              local!selectAll,
              count(save!value) = count(local!allOptions)
            )
          }
        )
      }
    )