If an entity label contains white space at the beginning or end, form validation will fail, if you select this entity.

In entityreference_autocomplete_validate_entityreference(), the submitted label string is sent through drupal_explode_tags(). It will trim the string, so if you have a label string like ' Landeslobbybeauftragte des deutschen Vorstandes (68109)' you'll get an array like this

array(
  'Landeslobbybeauftragte des deutschen Vorstandes (68109)',
)

. Later in the validation handler, a property condition on the label field is added on the EFQ validating the form input. Since the white space has been removed from the title earlier, no results are found and the validation fails.

Steps to reproduce:

1. Create a node with title " Example" (note the white space at the beginning).
2. Create a form containing an ERA form element, where you could select the node you just created.
3. Select the node you just created.
4. Submit the form.

Actual result:

You get an error There are no entities matching " Example". The form is not submitted.

Expected result:

You can submit the form.

Comments

FeyP created an issue. See original summary.

  • slv_ committed a210124 on 7.x-1.x
    Issue #2693391: Form validation fails, if entity label contains white...
slv_’s picture

Status: Active » Closed (fixed)

Hi Feyp, just for reporting the problem.

It's a bit of a very unlikely scenario, but patched nevertheless. It's on 7.x-1.x branch, so it'll go into the next release.