Webform dynamic select options based upon another element's state

by Luke A. Leber   Last Updated June 13, 2019 03:07 AM

Say there are two select elements with dynamic options (via an options alter hook, sourced from an external resource): A and B. There is also a datasource that provides a relationship that determines the options in B that should shown when a particular selection in A is chosen.

The source data for each element in addition to the relationship data source is not able to be predicted or controlled by Drupal.

For example:

A Options at a particular instant

| name | code |
| Group 1 | 1 |
| Group 2 | 2 |
| Group 3 | 3 |

B options at a particular instant

| name | code |
| Thing 1 |  1 |
| Thing 2 | 2 |
| Thing 3 | 3 |

The relationships at any given time.

| group | thing |
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
| 3 | 3 |

So if group 1 is selected for A, then things 1, 2, and 3 should be options for B

If group 2 is selected for A, then things 1 and 2 should be options for B

If group 3 is selected, then only thing 3 should be an option for 3.

We are currently implementing this requirement through the core FAPI and ajax callbacks, but would like to covert it to use Webforms.

What would be the recommended approach to take in order to solve this with Webforms? Please bear in mind that modifying the source data is not an option, as it is not able to be predicted nor controlled by our unit and adjustments must be reflected in realtime.

Tags : 8 webforms


Related Questions


Updated January 05, 2019 15:07 PM

Updated April 17, 2018 15:07 PM

Updated April 18, 2018 17:07 PM

Updated April 23, 2018 16:07 PM

Updated May 08, 2018 09:07 AM