Currently I am using entityreference module 1.1 stable version.

There is a field pointing to a node content type.

Field configurations are as follow:
Label: Contact
Required: yes
Number of values: unlimited
autocomplete widget

When on a node that has this field is submitted, the node add/edit form is submited with it empty, the error message on screen is: field is required
Note that there is no label mentioned, making it a bit difficult to find the field in large forms (even though the fields is highlighted in red).

Comments

ndobromirov’s picture

Assigned: ndobromirov » Unassigned
Status: Active » Needs review
StatusFileSize
new568 bytes

I tracked the issue to the fact that the #title property in the different autocomplete widgets is left empty for some reason.
Created a simple patch that fixes it.

Status: Needs review » Needs work
ndobromirov’s picture

Status: Needs work » Needs review

Requesting retest, because on a local environment Drupal 7.25 and the latest stable versions for ctools entity and entityreference, all the tests pass with OK.

ndobromirov’s picture

Status: Needs review » Needs work
seanb’s picture

Applied the patch manually and it seems to work. Not sure I'm a fan of the title suffix, but it is still better then not having any feedback.

artusamak’s picture

Version: 7.x-1.1 » 7.x-1.x-dev
Status: Needs work » Needs review
StatusFileSize
new883 bytes

Here a patch that should solve it the right way.

chewie’s picture

last patch looks good. Work for me

mrharolda’s picture

Status: Needs review » Reviewed & tested by the community

Checked; with untranslated and translated field labels.

mforbes’s picture

This issue is not specific to entityreference fields. Try making a content type with only text fields, all required, some with "number of values: 1" and some "number of values: [2-10 or unlimited]". If you submit the node/add form completely blank to generate required messages for each field, the single-value fields say "Foo field is required." while the multi-value fields say "field is required."

I think this is because with a multi-value field, you have 1 visible label for the whole table, and the actual inputs within the table rows do not have a visible label (save for the red asterisk, which is silly and redundant since the visible label also has a red asterisk, but that's another story). It's the actual input that is tested during the "required" check, and when the test fails, that input's label (which doesn't exist) is used for the "[label] field is required" error message.

The code that builds the error message needs to detect that the input has no label but the parent element (the table) does have a label, and use that parent label instead.

This also occurs when the "Add another item" button is clicked while there is no value in the first input. The AJAX operation results in a local "field is required." error message right above the input (as opposed to at the top of the form, where it will appear upon submitting the whole form). The code that builds the error message for this local rendering also needs to be fixed.

Therefore, perhaps this is actually a bug in the core field module, so that is where a patch should be applied, not here.

EDIT: To clarify, when I say "Add another item" obviously this only applies to unlimited cardinality. However, the original issue (submitting the whole form) actually exists even if the number of values is set to an integer like 2-10.

alexiswatson’s picture

Status: Reviewed & tested by the community » Closed (duplicate)

A fix is coming in core with a backport for D7, effectively making this a duplicate of https://www.drupal.org/node/980144