Validating multiple fields of the same entity
There are three types of validations:
1. Requiring at least one of several fields available on a page
2. Repetition of values on multiple fields
3. Unique values on multiple fields
They work on several fields of the same bundle. The configuration is a little strange, we need add the same validator to each field instance, and make sure the "group name" in the validation rule is the same one.
For example, we have three fields:
field1, field2, field3,
we want to add "Require at least one of several fields" on those fields.
Then we need add this validator to field1, on the validation rule config page, enter group name, such as "group_name_1".
Then we need add this validator to field2, on the validation rule config page, enter group name, such as "group_name_1".
Then we need add this validator to field3, on the validation rule config page, enter group name, such as "group_name_1".
It is a little strange,and the error message may appear three times. However, it works. It is the best way to support multiple fields.
Maybe we could improve those 3 validators in the future.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.