0

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.

2

No one has contributed back a solution for Drupal 8. I think the best approach is going to be to organize cascading select menus using a CSV and implementing something like Cognito form's cascading dropdowns menus.

Another supported approach is the Webform Simple Hierarchical Select module but it requires a taxonomy.

  • Hi, thanks for following up. We are more than willing to do custom development to get this implemented. Can we somehow trigger rebuilds of a webform similar to how we are doing it with FAPI? – Luke A. Leber Jun 13 at 13:37
  • 3
    Webform in D8 is built using FAPI and you can add Ajax callbacks to custom webform elements. – jrockowitz Jun 13 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.