There is a compatibility issue with the Conditional Fields module when setting an ERVW field to required.
Steps to reproduce:
Create an Entity Reference field using the Entity Reference View Widget - make this field required.
Set up a dependency with the Conditional Fields module so that this field is only visible if a certain condition is met.
Upon submitting a node where the condition was NOT met (ie ERVW is not visible to the user) a "field required" error message is displayed and the node can not be submitted. The Conditional Fields module normally ignores required fields in this case, but the way that ERVW is setting the error message is causing a problem.
It think the basic fix is to set the error using "form_error" rather than "form_set_error"
In entityreference_view_widget.module line 314 what is the purpose of this if block?
if (isset($form_existing['#field_parents']) && empty($form_existing['#field_parents'])) {
form_set_error($settings['element'], t('@f field is required.', array('@f' => $settings['instance']['label'])));
}
else {
// Modules utilizing #field_parents like Inline Entity Form requires different sort of form error.
form_error($element, t('@f field is required.', array('@f' => $settings['instance']['label'])));
}
In hunting around it looks like this code was modified a bit with this issue:
https://www.drupal.org/node/2355333
https://www.drupal.org/files/issues/entityreference_view_widget-ervw-doe...
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | conditional-required-2570441-2.patch | 861 bytes | skylord |
Comments
Comment #2
skylord commentedGot the same bug. Actually it's caused by incorrect original form_set_error not using full ['#parents'] path. form_error from mentioned patch does it right and when used as general solution also fixes this bug. Patch attached.