Cascading Dropdown to 3 levels

Certified Senior Developer

I am trying to implement 3 level cascading dropdown fields. 'State' dropdown field will have choices based on 'country' selected and 'City' dropdown field will have choices based on 'State' selected. I have created choices for 'States' field using choose() function. But not sure how to create choices for 'City' field. It would be great if anyone can respond to this.

Note: I am using localVariables for all the data. Not querying to DB. This is only for testing purpose.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I have to agree with Mike quite strongly on the limitations of the choose function here.  The difficulty is that with choose, you have to know beforehand how many options you will have, and always have to have exactly that many options, or you invite aberrant behavior at the very best.

    The goal is to make choiceLabels and choiceValues.  You could create a helper rule that just outputs a list of cities given a state input.  That could actually run on a simple choose function, but return lists of Text.  That gets you labels.  Then call the same rule, but a!forEach(items: rule!yourHelperRule(ri!state), expression: fv!index) to get the choiceValues.  Maybe that would work?

Reply
  • 0
    Certified Lead Developer

    I have to agree with Mike quite strongly on the limitations of the choose function here.  The difficulty is that with choose, you have to know beforehand how many options you will have, and always have to have exactly that many options, or you invite aberrant behavior at the very best.

    The goal is to make choiceLabels and choiceValues.  You could create a helper rule that just outputs a list of cities given a state input.  That could actually run on a simple choose function, but return lists of Text.  That gets you labels.  Then call the same rule, but a!forEach(items: rule!yourHelperRule(ri!state), expression: fv!index) to get the choiceValues.  Maybe that would work?

Children
No Data