I am trying cascading dropdown with query rules. I have this SAIL expression but

I am trying cascading dropdown with query rules. I have this SAIL expression but it doesn't work: could you help me? Thanks!
=load(
local!selectedFoodType: tointeger(null),
local!fruitChoice:tointeger(null),
local!vegetableChoice,
a!formLayout(
label: "SAIL Example: Cascading Dropdowns",
firstColumnContents: {
a!dropdownField(
label: "Food Type",
choiceLabels: rule!getTypeExp(),
choiceValues: rule!getTypeExp(),
placeholderLabel: "--- Select Food Type ---",
value: local!selectedFoodType,
saveInto: local!selectedFoodType
),
if(local!selectedFoodType = "",{},
a!dropdownField(
label: "Fruits",
choiceLabels:rule!getFailureDescription(local!selectedFoodType),
choiceValues: rule!getFailureDescription(local!selectedFoodType),
placeholderLabel: "--- Select Fruit Type ---",
value: local!fruitChoice,
saveInto: local!f...

OriginalPostID-96788

OriginalPostID-96788

  Discussion posts and replies are publicly visible

Parents
  • Your dropdown values must always match an item in the choiceValues array. So when you're switching the first dropdown, the previously selected value in the second dropdown no longer matches any item in the choiceValues array, and errors out. The error message isn't return correctly right now (we have an open ticket to fix this).

    Therefore, you should clear out the value of the second dropdown whenever the user selects something in the first dropdown. In your case, you would update the saveInto field in your first dropdown to be:

    saveInto: {
    ri!choiceFoodType,
    ri!fruitChoice << rule!ucReturnFirstInput(null, _)
    }

    Look up rule!ucReturnFirstInput in the SAIL Recipes page for its definition. The same pattern is used in a couple places, so this will be a useful utility rule to have.
Reply
  • Your dropdown values must always match an item in the choiceValues array. So when you're switching the first dropdown, the previously selected value in the second dropdown no longer matches any item in the choiceValues array, and errors out. The error message isn't return correctly right now (we have an open ticket to fix this).

    Therefore, you should clear out the value of the second dropdown whenever the user selects something in the first dropdown. In your case, you would update the saveInto field in your first dropdown to be:

    saveInto: {
    ri!choiceFoodType,
    ri!fruitChoice << rule!ucReturnFirstInput(null, _)
    }

    Look up rule!ucReturnFirstInput in the SAIL Recipes page for its definition. The same pattern is used in a couple places, so this will be a useful utility rule to have.
Children
No Data