Skip to main content
Known Participant
Dec 5, 2024 9:32 PM UTC
Question

Dropdown Field Value Selection impact on another Dropdown Field

Lets say I have an Interface with 2 Dropdowns. Lets call them Dropdown1 and Dropdown2. Both have Values Yes and No.

If User selects Dropdown1 with Value Yes, then Dropdown2 should automatically be set to No and it should be greyed out or disabled so that User cannot change it to Yes.

Please advise how we can accomplish this.

Regards,

Mahesh

5 replies

acaciob596205
Participating Frequently
Dec 6, 2024 12:23 AM UTC

HI [mention:f715d2a5beee447f95815c5be14799c3:e9ed411860ed4f2ba0265705b8793d05] ,

There are many different ways to achieve the expected result. I hope this snippet provides you with some ideas.


a!localVariables(
  local!values: { true(), false() },
  local!labels: { "Yes", "No" },
  local!dropd1: null(),
  local!dropd2: null(),
  a!columnsLayout(
    columns: {
      a!columnLayout(
        contents: a!dropdownField(
          label: "Dropdown 1",
          choiceLabels: local!labels,
          choiceValues: local!values,
          placeholder: "Select a value",
          value: local!dropd1,
          saveInto: {
            local!dropd1,
            a!save(
              local!dropd2,
              a!match(
                value: local!dropd1,
                whenTrue: fv!value,
                then: false(),
                default: null()
              )
            )
          }
        )
      ),
      a!columnLayout(
        contents: a!dropdownField(
          disabled: and(local!dropd1, not(local!dropd2)),
          label: "Dropdown 2",
          choiceLabels: local!labels,
          choiceValues: local!values,
          placeholder: "Select a value",
          value: local!dropd2,
          saveInto: { local!dropd2 }
        )
      )
    }
  )
)

Acacio B.

Known Participant
Dec 6, 2024 10:33 PM UTC

Thank you [mention:a03094de66594684aa5d3b48e114a5dc:e9ed411860ed4f2ba0265705b8793d05] , your solution worked.  Appreciate your help here.

prasantap0900
Participating Frequently
Dec 6, 2024 4:59 AM UTC

An example

a!localVariables(
  local!drop1: { "Yes", "No" },
  local!drop2: { "Yes", "No" },
  local!save,
  local!save2,
  {
    a!dropdownField(
      placeholder: "please select",
      choiceLabels: local!drop1,
      choiceValues: local!drop1,
      value: local!save,
      saveInto: local!save
    ),
    a!dropdownField(
      placeholder: "please select",
      choiceLabels: local!drop2,
      choiceValues: local!drop2,
      value: if(local!save = "yes", "No", ""),
      saveInto: a!save(local!save2, save!value),
      disabled: if(local!save = "yes", true, false)
    )
  }
)

Known Participant
Dec 6, 2024 10:34 PM UTC

Thank you [mention:06d3c31e5c9d4c979813e345053c3afc:e9ed411860ed4f2ba0265705b8793d05] , appreciate the help here.

gayatria0439
Participating Frequently
Dec 6, 2024 6:19 AM UTC

Hi [mention:f715d2a5beee447f95815c5be14799c3:e9ed411860ed4f2ba0265705b8793d05] ,

a!localVariables(
  local!choice: { "Yes", "No" },
  local!value1,
  local!value2: null(),
  a!columnsLayout(
    columns: {
      a!columnLayout(
        contents: a!dropdownField(
          label: "Dropdown 1",
          choiceLabels: local!choice,
          choiceValues: local!choice,
          placeholder: "Select a value",
          value: local!value1,
          saveInto: { local!value1,  }
        )
      ),
      a!columnLayout(
        contents: a!dropdownField(
          label: "Dropdown 2",
          choiceLabels: local!choice,
          choiceValues: local!choice,
          placeholder: "Select a value",
          value: if(
            local!value1 = "Yes",
            a!defaultValue(value: local!value2, default: "No"),
            local!value2
          ),
          saveInto: { local!value2 },
          disabled: local!value1 = "Yes"
        )
      )
    }
  )
)