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
  • 0
    Certified Associate Developer

    Hey

    This code helps achieve the functionality you're looking for using a multiple dropdown. All the options are stored in a local variable and preselected by default. To deselect, you can simply click the “×” icon on the multiple dropdown field, which clears the selection. This gives a clean and user-friendly way to toggle selections without extra UI controls.

  • 0
    Certified Associate Developer
    in reply to Megha Ramnani

    yeah thanks for the code. but what if user want to select all the options again. customer want option as select all and deselect all along with the options

  • 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)
          }
        )
      }
    )

Reply
  • 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)
          }
        )
      }
    )

Children
No Data