Problem/Motivation
Empty submitted values for #type weight / delta elements cause false "not allowed" validation errors. When a form with multi-value fields (e.g. entity reference fields using the Inline Entity Form widget) is submitted, the weight/delta elements can have an empty string #value if the user input for those elements is missing. This triggers performRequiredValidation() to throw "The submitted value in the ... element is not allowed" because the empty string is not in the element's #options array.
Steps to reproduce
1. Create a content type with a multi-value entity reference field using the "Inline entity form - Complex" widget.
2. Add multiple referenced entities to the field.
3. Save the node — the weight/delta elements in the IEF widget submit with empty values, triggering the "not allowed" error.
Proposed resolution
In \Drupal\Core\Form\FormValidator::doValidateForm(), add a check for weight/delta elements: if the element key is delta or has the #is_weight property set to TRUE, and its submitted #value is an empty string, restore it to the element's #default_value (falling back to 0). This covers both delta and _weight named elements used by multi-value field widgets and inline entity forms, and prevents false "not allowed" validation errors when the weight element's submitted value is empty.
Issue fork drupal-3605691
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
falc0 commentedComment #4
smustgrave commentedThank you for reporting, can we expand an existing test to show the issue please.