Description
With the Field Conditional State module you can change the state of any supported fields form element depending on the content of other fields. This is done by providing an UI for Drupal's States API.
All the changes made to a form by FCS (Field Conditional States) utilize only the States API and therefore are clientside only.
This module requires Drupal 7.14 or higher
Example usages
The Field Conditional State module can be used when:
- you have a text field you only want to be enabled when a certain checkbox is checked
- you want to show a different set of fields depending on the value(s) selected in a certain select list
- ..to be continued..
Terminology or "How does it work?"
If you already know the States API and how it works, you may skip the following.
The States API provides a set of states that can be applied to form elements. Some of them "are not fully implemented [by Drupal's Core] and may not change anything on the element" and aren't supported by FCS. The working states that are supported by FCS are:
- visible / invisible - Hides/Shows a form element
- enabled / disabled - Grays out a form element
- required / optional - Makes a form element required to be able to submit the form
- checked / unchecked - Checks/Unchecks a checkbox (of course only applicable to checkboxes)
Fields to which these states will be applied, are called target fields or controled fields.
To trigger these states there is a different set of trigger states (not to be confused with the states described above) that will trigger a state when applied to a control field:
- empty - Triggers when the control field is empty
- filled - Triggers when the control field is not empty
- checked - Triggers when the control field is checked
- unchecked - Triggers when the control field is not checked
- value - Triggers when the control field's value is equal to a given string
- !value - Triggers when the control field's value is NOT equal to a given string
All of them are supported as long as they make any sense for the widget of the used control field. For example it doesn't make any sense to wait for a text field to be checked or for a checkbox to have the value "Hello World". So most (if not all) fields will only use a subset of these trigger states.
Fields
When creating a conditional state you will always have something like this:
Make field foo1 visible2, when field bar3 has the value4 "Hello"
or
Make field customtext1 required2, when field check3 is checked4.
To use the terminology introduced in this chapter:
1target field/controled field
2state
3control field
4trigger state
Supported widgets
Field Conditional States supports the following widgets as control fields. Unless stated otherwise, all versions of the modules listed below should be supported.
- Core
- File
- Image
- Number
- Select list
- Single on/off checkbox
- Text area (multiple rows)
- Text field
- Email Field
- Text field
- Entity reference
- Autocomplete
- Autocomplete (Tags style)
- URL field
- External URL field
- Star Rating
- Star Rating (Version 1.1)
- Video Embed Field
- Video
As target fields all of the widgets listed above can be used and additionally:
- Core
- Check boxes/radio buttons
It's not possible to use these widgets as control fields!
We want to support as much widgets as possible. So, if you need a widget which isn't listed here to be supported by Field Conditional States, create a new Feature request in the issue queue and we'll try to add support for it.
Migration from old Field Conditional State module
First of all: Backup your database!!
The preferred method of migrating to the 2.x version is to uninstall the old module and delete the field-conditional-state module directory (important!) and then install the 2.x version.
Afterwards the states have to be recreated.
Alternatively it's possible to just delete the old modules directory create the new field_conditional_state directory and run update.php. The existing states will be automatically migrated and therefore aren't lost.
Project information
- Module categories: Site Structure, Developer Tools
- 1,721 sites report using this module
- Created by hass on , updated
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.
Releases
Development version: 7.x-2.x-dev updated 27 Jun 2015 at 08:33 UTC