Hello All,
I have a requirement where i have to create two dropdown fields but second dropdown will depend upon first. Suppose user selects one option from the first dropdown then according to that option second dropdown show options. one more thing is that i want second dropdown only appears when user choose option from first dropdown.
Kindly suggest how to achieve this.
Thanks in Advance
Discussion posts and replies are publicly visible
Hi gopalk0002You can achieve this by saving the values to be shown in the second drop-down on the selection of 1st drop-down and show the second one only after the first is selected. Make sure to do a null condition if the option is changed in the first one. Something like this.
load( local!dropdown1: {1,2,3}, local!value1, local!value2, local!dropdown2, { a!dropdownField( label: "Dropdown 1", placeholderLabel: "Please select", choiceLabels: local!dropdown1, choiceValues: local!dropdown1, value: local!value1, saveInto: { local!value1, a!save(local!value2,NULL), if(local!value1=local!dropdown1[1],a!save(local!dropdown2,{4,5,6}),a!save(local!dropdown2,{7,8,9})) } ), a!dropdownField( showWhen: not(rule!APN_isBlank(local!value1)), label: "Dropdown 2", placeholderLabel: "Please select", choiceLabels: local!dropdown2, choiceValues: local!dropdown2, value: local!value2, saveInto: local!value2 ) })
If the second dropdown is ever going to be required, you might want to replace "showWhen:" in ekanshj's example code with "disabled:" It helps the user not be shocked by the addition of a new field, but informs them of exactly how many inputs they're going to have to fill in and in what order.
UX is a bit more of an art than a science, though. You can try both approaches and see which you prefer.
I like the spirit of this answer.
Just note that ekanshj - for illustrative purposes, I assume - is loading the drop down values from hard-coded arrays in the SAIL. This will work fine for the example. However, in practical application, this can be a chore to maintain. Typically, a more flexible solution would be to retrieve those values from your reference data repository.
Thanks ekanshj for replying, if user selects second option or third option he will get same options in second dropdown. how can we configure it dynamically.
thanks
yes Correct. we will retrieve values from data repository.
yes this has to be dynamic in nature based on selection for that either you have to use database queries where based on your selection it will pass as input and fetch the relevant options or you can create a decision which can be configured as per input and gives out the output.
Thanks ekanshj I configured in that way only.