What is the best practice for a dynamic select list in Drupal 7?
- Create a Field with dummy options via the UI and overriding the options with
hook_form_FORM_ID_alter
or
- Creating a dynamic select list from scratch via a custom module with the
hook_form
or
- different approach?
Thanks
You could use Form API's #ajax (it used to be called
#ahah
in Drupal6) to do that.Here is an example for Drupal 7 (based on Examples for Developers) that shows two dropdowns where the first dropdown modifies the list of options of the second dropdown:
Source of file mymodule.module: