- Issue created by @raffaelj
I tested the module to validate fields for the core contact module. It works in general, but errors aren't assigned correctly. If one child field fails, all child fields are marked as invalid.
This happens with the 8.x-1 and with the 3.0 branch.
* create contact form
* create text field "test", allowed number of values: 3
* create a validation rule
* submit form with 2 invalid inputs and one valid input
* all three inputs are marked as invalid and the error message doesn't differentiate between them
I tested it with the 3.0 branch with the EqualTo constraint and in the 8.x branch with the BlocklistFieldValidationRule.
I tested it locally with the BlocklistFieldValidationRule and from the 8.x branch, but it should work the same in the 3.x branch.
After replacing
$context->addViolation($rule->getReplacedErrorMessage($params));
with
$context->buildViolation($rule->getReplacedErrorMessage($params))
->atPath((string) $params['delta'])
->addViolation();
the errors are assigned correctly and only the invalid fields are marked as invalid.
See also:
*
https://www.drupal.org/docs/drupal-apis/entity-api/entity-validation-api... →
* https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Entity%21...
As a nice side effect when using field_validation in combination with the core inline_form_errors module, the error messages at the top now point to #edit-field-test-{1,3}
instead of #edit-field-test
. Ideally these links should point to #edit-field-test-{1,3}-value
, but this is a task for another issue (here or in inline_form_errors module).
* [ ] copy/paste in many constraint and rule files
Active
1.1
Code