Skip to main content
pradeepb0001
June 7, 2021
Solved

how to save previous selected value of dropdown in local variables?

  • June 7, 2021
  • 4 replies
  • 1 view

Hi ,

    I am having a drop down with 4 choice values A,B,C,D. Based upon the value selected for Eg; D, a  section will appear below.

My requirement is

  1. when the drop down value selected is D, then below section should be refreshed i.e. set the section fields to null
  2. if the drop down value selected is either D to A or A to D or B to D or C to D , then below section should be refreshed i.e. set the section fields to null.
  3. if the drop down value selected is either B to A or A to C or B to C, then below section should not be refreshed.

so for this requirement i want to save the previous selected value of dropdown to compare with the latest selected value in order to do the refresh.

please provide your suggestions or any other idea to do this requirement.

Thanks in advance

Pradeep.B

Best answer by ankitab254

a!localVariables(
  local!dropdownValue:{"A","B","C","D"},
  local!selected,
  local!existingSelection,

  local!isSectionRefresh: if(local!selected="D", true(),
  if(and(local!selected="A",
  index(local!existingSelection,(count(local!existingSelection)-1),"")="D"),true(),
  false()
  )
  ),
  
  {
    a!dropdownField(
      label:"Dropdown",
      choiceLabels: local!dropdownValue,
      choiceValues: local!dropdownValue,
      placeholder: "Please select",
      value: local!selected,
      saveInto: {
        local!selected,
        a!save(local!existingSelection,
        append(local!existingSelection,local!selected))
      }
    ),
    a!textField(
      label:local!existingSelection,
      value: if(local!isSectionRefresh, null, local!selected)
     
    )
  }
)

You can try something similar to this

4 replies

June 7, 2021

a!localVariables(
  local!dropdownValue:{"A","B","C","D"},
  local!selected,
  local!existingSelection,

  local!isSectionRefresh: if(local!selected="D", true(),
  if(and(local!selected="A",
  index(local!existingSelection,(count(local!existingSelection)-1),"")="D"),true(),
  false()
  )
  ),
  
  {
    a!dropdownField(
      label:"Dropdown",
      choiceLabels: local!dropdownValue,
      choiceValues: local!dropdownValue,
      placeholder: "Please select",
      value: local!selected,
      saveInto: {
        local!selected,
        a!save(local!existingSelection,
        append(local!existingSelection,local!selected))
      }
    ),
    a!textField(
      label:local!existingSelection,
      value: if(local!isSectionRefresh, null, local!selected)
     
    )
  }
)

You can try something similar to this

pradeepb0001
June 7, 2021

thank u [mention:08e7de8b1e874627b6bb409dbce962cd:e9ed411860ed4f2ba0265705b8793d05]

mikes0011
Brainy
June 7, 2021

The above posted code will work (though i'm unclear what "should be refreshed" really implies from your initial requirement description); however I'd personally recommend simplifying if possible and just using stacked saveIntos to save a single "last value" historical copy whenever the dropdown is changed.  You can then (i assume) store your logic for the "refresh" condition in a subsequent local variable, which will refresh anytime either of the earlier values gets changed.

a!localVariables(
  local!values: { "A", "B", "C", "D" },
  local!currentSelection,
  local!oldSelection,

  local!isRefresh: if(
    isnull(local!oldSelection),
    "",
    "" /* put refresh logic here */
  ),

  {
    a!dropdownField(
      label: "Dropdown",
      choiceLabels: local!values,
      choiceValues: local!values,
      placeholder: "--select a value--",
      value: local!currentSelection,
      saveInto: {
        a!save(
          local!oldSelection,
          local!currentSelection
        ),
        a!save(
          local!currentSelection,
          save!value
        )
      }
    )
  }
)

The Expression Guru
pradeepb0001
June 8, 2021

thank u [mention:b45a4f6a20b14a008e4e0ec732a8bf98:e9ed411860ed4f2ba0265705b8793d05]