Single-value autocomplete widgets don't warn about field cardinality, lose data silently

Created on 8 March 2018, almost 7 years ago
Updated 21 February 2024, 10 months ago

Problem/Motivation

If a reference field has a limited cardinality and uses the autocomplete widget in the entity form, then the user can enter more values than the field allows, and the surplus values are discarded silently when the form is submitted.

Steps to reproduce

To reproduce:

- create a reference field, say on article nodes
- set its widget to autocomplete
- create a new article node
- enter one node title in the widget and let it autocomplete
- enter a comma and start typing another node title
- the widget lets you do this: it should not.
- save the node
- the node saves: it should not. The form should fail validation
- edit the node: only the last entered node title is shown
- check the DB: only the last entered node was saved in the field value

Proposed resolution

The form should fail validation when too many values have been entered in the autocomplete widget.

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated 1 day ago

Created by

πŸ‡¬πŸ‡§United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request β†’ as a guide.

    This could use an issue summary update. Mainly what is the proposed solution to solve the issue? I see steps to reproduce but what was the solution decided upon? WIll help committers later?

  • Status changed to Needs review almost 2 years ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Added detail to IS.

  • Status changed to Needs work almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Can someone verify if this is still an issue?

    Just tested in Drupal 10.1 with a standard install
    Changed article tags field to cardinality of 1
    Created an article by adding TestA then TestB waiting for the autocomplete icon to go away each time
    When I clicked save I get

    Tags: this field cannot hold more than 1 values.

  • πŸ‡ΊπŸ‡ΈUnited States codechefmarc

    I also just tested on 10.0.3 with a standard install, similar details as smustgrave, and I also get the "Tags: this field cannot hold more than 1 values." message when trying to save the article. So, perhaps this is fixed in Drupal 10 which is great to hear.

  • πŸ‡ΊπŸ‡ΈUnited States GuyPaddock

    Can someone confirm that there are tests for this behavior in 10.x? If not, I can at least reroll for the added test coverage.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    From what I can tell searching for "hold more than" there are instances of test coverage. But this constraint in fieldItemList has been in for 5 years? That doesn't right.

    Want to make sure we can move credit for everyone that helped work on this.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Brought this up in the #bugsmash channel and others reported they were able to replicate

    From @rkoller

    i’ve added an entity reference field to the article content type and picked the reference type basic page. and field settings were limited to 1. and under manage form display i’ve used the default autocomplete option.

    and

    changed the option from autocompleteto autocomplete (tag style) in manage form display. with that option active i get the limited to 1 warning and i am unable to proceed to save the form. if i switch back to autocomplete i am again able to save more than one tag and just the last is saved as described in the issue summaries steps to reproduce section

  • πŸ‡¦πŸ‡ΊAustralia pameeela

    Yeah, confirmed it occurs with the regular 'Autocomplete' widget and not the tags style one.

  • πŸ‡ΊπŸ‡ΈUnited States GuyPaddock

    GuyPaddock β†’ changed the visibility of the branch 2796341-entity-reference-field to hidden.

Production build 0.71.5 2024