The module is designed for setting up Form API #States over configuration.
Installation
Install the module as you would normally install a contributed Drupal module. Visit https://www.drupal.org/node/1897420 for further information.
Configuration
- Go to Form States Configurations page (path
/admin/structure/form-states-config). - Hit 'Add Form States config' link.
- In 'Form ID' field put ID of a form which requires form states adjustments.
- In 'Form States' field add form states.
- Hit 'Save' button.
Example
Let's imagine user account has "Contact settings" (contact) and "Locale settings" (timezone) fields. "Administrator" (administrator) user role is only user role for which "Contact settings" and "Locale settings" fields should be shown on User Registration form. Create new Form States Configuration with next values:
- Form ID: user_register_form
- Form States:
contact:
visible:
:input[name="roles[administrator]"]:
- checked: TRUE
timezone:
visible:
:input[name="roles[administrator]"]:
- checked: TRUE
For more examples visit https://www.drupal.org/docs/drupal-apis/form-api/conditional-form-fields.
Notes:
1. Value for "Form States" must have a valid YAML format.
2. If it requires to add #states to nested array, for example $form['field_region']['widget']['#states'] then use field_region.widget.
3. Created configurations are exportable. Use `drush cim` to do that. Each of configuration will be exported to the config directory as form_states_config.form_states_config.[form_id].yml files.
References:
- https://www.drupal.org/docs/drupal-apis/form-api/conditional-form-fields
Project information
- Project categories: Developer tools
- Created by alunyov on , updated
Stable releases for this project are covered by the security advisory policy.
There are currently no supported stable releases.
Releases
Updated requirements for core version + README.md
