How do I reset a dropdown value on radio change?

I have the following:

a!localVariables(
  local!countries: rule!PT_GetAvailableCountries(),
  local!selectedCountry: rule!PT_GetAvailableCountries()[1],
  local!states: rule!PT_GetStateByCountry(local!selectedCountry),
  a!formLayout(
    label: "Create Customer",
    contents: {
      a!columnsLayout(
        columns: {
          a!columnLayout(
            contents: {
              a!textField(
                label: "First Name",
                labelPosition: "ABOVE",
                value: ri!record['recordType!{cf9a6a37-c43d-422f-b4f7-bef6f0e8d9a3}PT Customer.fields.{421eacda-bfa9-4e18-8a6f-4428e01b5e23}firstName'],
                saveInto: ri!record['recordType!{cf9a6a37-c43d-422f-b4f7-bef6f0e8d9a3}PT Customer.fields.{421eacda-bfa9-4e18-8a6f-4428e01b5e23}firstName'],
                characterLimit: 30,
                required: false
              ),
              a!textField(
                label: "Last Name",
                labelPosition: "ABOVE",
                value: ri!record['recordType!{cf9a6a37-c43d-422f-b4f7-bef6f0e8d9a3}PT Customer.fields.{90a4be44-9fc7-4644-abfc-80ebe7628e78}lastName'],
                saveInto: ri!record['recordType!{cf9a6a37-c43d-422f-b4f7-bef6f0e8d9a3}PT Customer.fields.{90a4be44-9fc7-4644-abfc-80ebe7628e78}lastName'],
                characterLimit: 30,
                required: false
              ),
              a!textField(
                label: "Phone",
                labelPosition: "ABOVE",
                value: ri!record['recordType!{cf9a6a37-c43d-422f-b4f7-bef6f0e8d9a3}PT Customer.fields.{fbc5f2ed-2d1d-4ccf-b036-9660fa9af1ff}phone'],
                saveInto: ri!record['recordType!{cf9a6a37-c43d-422f-b4f7-bef6f0e8d9a3}PT Customer.fields.{fbc5f2ed-2d1d-4ccf-b036-9660fa9af1ff}phone'],
                characterLimit: 20,
                required: false
              ),
              a!integerField(
                label: "Age",
                labelPosition: "ABOVE",
                value: ri!record['recordType!{cf9a6a37-c43d-422f-b4f7-bef6f0e8d9a3}PT Customer.fields.{bd3f98b3-e7fc-44bc-9bfd-88468c8e2ef9}age'],
                saveInto: ri!record['recordType!{cf9a6a37-c43d-422f-b4f7-bef6f0e8d9a3}PT Customer.fields.{bd3f98b3-e7fc-44bc-9bfd-88468c8e2ef9}age'],
                required: false
              ),
              a!radioButtonField(
                label: "Country",
                labelPosition: "ABOVE",
                choiceLabels: local!countries,
                choiceValues: local!countries,
                value: { local!selectedCountry },
                saveInto: { local!selectedCountry },
                choiceLayout: "COMPACT",
                choiceStyle: "STANDARD",
                validations: {}
              ),
              a!dropdownField(
                label: "State/Province",
                labelPosition: "ABOVE",
                placeholder: "--- Select a Value ---",
                choiceLabels: local!states['recordType!{aff1d458-739c-4f1d-ac99-b00285331451}PT StateOption.fields.{a21553bd-5cea-488d-83bb-1f41f1390eef}combinedState'],
                choiceValues: local!states['recordType!{aff1d458-739c-4f1d-ac99-b00285331451}PT StateOption.fields.{6c9cc54a-59ad-4b8b-8bea-1150f50a2b56}stateId'],
                value: if(
                  contains(
                    local!states['recordType!{aff1d458-739c-4f1d-ac99-b00285331451}PT StateOption.fields.{6c9cc54a-59ad-4b8b-8bea-1150f50a2b56}stateId'],
                    ri!selectedState
                  ),
                  ri!selectedState,
                  null,
                  
                ),
                saveInto: { ri!selectedState,  },
                searchDisplay: "AUTO",
                validations: {}
              ),
              a!paragraphField(
                label: "Description",
                labelPosition: "ABOVE",
                value: ri!record['recordType!{cf9a6a37-c43d-422f-b4f7-bef6f0e8d9a3}PT Customer.fields.{a0110976-2b24-4156-a7b6-c91f4ecfd8ef}description'],
                saveInto: ri!record['recordType!{cf9a6a37-c43d-422f-b4f7-bef6f0e8d9a3}PT Customer.fields.{a0110976-2b24-4156-a7b6-c91f4ecfd8ef}description'],
                refreshAfter: "UNFOCUS",
                height: "MEDIUM",
                validations: {}
              )
            }
          )
        }
      )
    },
    buttons: a!buttonLayout(
      primaryButtons: {
        a!buttonWidget(
          label: "Submit",
          submit: true,
          style: "PRIMARY",
          validate: true
        )
      },
      secondaryButtons: {
        a!buttonWidget(
          label: "Cancel",
          value: true,
          saveInto: ri!cancel,
          submit: true,
          style: "NORMAL",
          validate: false
        )
      }
    )
  )
)

When the country value changes, the display value for State/Province changes, but the ri!selectedSate value does not reset to null.
How can I get ri!selectedState to reset it's value?

  Discussion posts and replies are publicly visible

Parents
  • If you want to reset ri!selectedSate to null on change of radio selection, here is the code for that.

    a!radioButtonField(
    label: "Country",
    labelPosition: "ABOVE",
    choiceLabels: local!countries,
    choiceValues: local!countries,
    value: { local!selectedCountry },
    saveInto: { local!selectedCountry, a!save(ri!selectedSate, null) },
    choiceLayout: "COMPACT",
    choiceStyle: "STANDARD",
    validations: {})

    Also you may use following to refresh local variable when the referenced variable changes.

    a!localVariables(
      local!countries: rule!PT_GetAvailableCountries(),
      local!selectedCountry: a!refreshVariable(value: local!countries),
      local!states: a!refreshVariable(value: rule!PT_GetStateByCountry(local!selectedCountry)),
      a!formLayout(
        label: "Create Customer",
        contents: {
          a!columnsLayout(


  • The refreshVariable doesn't seem to do anything in this instance.

    However, the saveInto for the radioButtonField works as expected.

    Thanks,

    pete

  • 0
    Certified Lead Developer
    in reply to petel0001

    To see what a!refreshVariable() is doing, just remove it and refer the direct value, and you will understand how it works.

    To shed some more light ...

    refreshOnReferencedVarChange - parameter doing the trick here. It's set as true by default and hence the local variables are getting refreshed on ReferencedVarChange.

    refreshOnReferencedVarChange (Boolean): When true, the value of this local variable will be refreshed each time the value of any variable it references within the value parameter is updated. To refresh the local variable when another variable that is not used within value changes, use refreshOnVarChange. Default: true.

  • I don't need to worry about a!refreshVariable().

    The SaveInto mentioned previously solves the issue for me.

Reply Children