multipledropdownfield component saving values in an unexpected order

I am noticing some behavior for the multipledropdown field component that seems unexpected to me. I have included an interface code snippet below, which is what the following example is based off of.

The issue is this: When I select any value from the muldipledropdownfield in the code below, the most recent selection is added to the end of the array in local!selectedColumnsToDisplay. However, when I select a second value, the index of the previous selection changes, and it moves to the position that it is in the choiceValues array.

For example, when the page loads the value of local!selectedColumnsToDisplay is {"Three", "Four"}. Then, I select "One" from the dropdown. Now the value of local!selectedColumnsToDisplay is {"Three", "Four", "One"}. Then, I select "Two" from the dropdown. Now the value of local!selectedColumnsToDisplay is {"One", "Three", "Four", "Two"}. The value "One" has jumped from the end of the array in local!selectedColumnsToDisplay to the beginning.

Why is this occurring? How can I get the values to save in the order that they are selected?

The behavior that I want and that I would expect to see, is that it save the values in the order that they are selected.


a!localVariables(
  local!selectedColumnsToDisplay: {"Three", "Four"},
  {
    a!multipleDropdownField(
      label: "Columns To View",
      labelPosition: "COLLAPSED",
      choiceLabels: {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"},
      choiceValues:  {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"},
      value: local!selectedColumnsToDisplay,
      saveInto: {
        local!selectedColumnsToDisplay,
      },
      validations: {}
    ),
    a!paragraphField(
      value:  local!selectedColumnsToDisplay,
      readOnly: true
    )
  }
)

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hi walkers,

    I added few more lines of code and tested. Looks like its working for me ,i tested few scenarios. Please test and let me know if  this  helps. Thanks, barat

    a!localVariables(
      local!prevselectedColumnsToDisplay:{"Three", "Four"},
      local!newcols:"",
      a!formLayout(
      label: "Form",
      contents: {
    
        a!localVariables(
          local!selectedColumnsToDisplay: local!prevselectedColumnsToDisplay,
          {
            a!multipleDropdownField(
              label: "Columns To View",
              labelPosition: "COLLAPSED",
              placeholder: "please select options",
              choiceLabels: {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"},
              choiceValues: {"One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight"},
              value: local!selectedColumnsToDisplay,
              saveInto: {
                local!selectedColumnsToDisplay,
                a!save(local!newcols,difference(local!selectedColumnsToDisplay, local!prevselectedColumnsToDisplay)),
                a!save(local!prevselectedColumnsToDisplay,append(local!prevselectedColumnsToDisplay,local!newcols)),
              },
              validations: {}
            ),
            a!paragraphField(
              value: local!prevselectedColumnsToDisplay,
              readOnly: true
            )
          }
        )
      },

Reply Children
No Data