We currently have the following code - FYI there are hundreds of these conditions:
if (feathery.fields[‘a’].equals(‘Apple’))
feathery.fields[‘c’].options = [‘Carrot’,‘Cashew’];
if (feathery.fields[‘a’].equals(‘Apricot’))
feathery.fields[‘c’].options = [‘Cherry’,‘Cantaloupe’];
if (feathery.fields[‘a’].equals(‘Avocado’))
feathery.fields[‘c’].options = [‘Cabbage’,‘Cucumber’];
if (feathery.fields[‘a’].equals(‘Asparagus’))
feathery.fields[‘c’].options = [‘Celery’,‘Corn’];
Field A and Field C are both multi select drop-downs.
Currently, when any value is selected in Field A, then the last selected value renders the available dropdown values for Field C.
How do we adjust the code so that if any combination of Apple, Apricot, Avocado, or Asparagus are selected in Field A, then C renders all of the corresponding dropdown values? (FYI The actual code has hundreds of Field A values and thousands of corresponding Field C values).
You would use the same logic but adjust the combinations in the if statement and set different combinations for c.options. For a large number of conditions, you might want to optimize it to handle multiple combinations. You can consider doing this through a mapping object, Map or Set. We recommend exploring more JavaScript documentation and resources on managing complex conditions and data structures efficiently.
Is there a simple way of doing this using the .includes function? For example, rather than allocate for all of the combinations, something to the effect that if Field A includes any value, then Field C would include the combination of all of the corresponding values.