An entity reference field with allowed number of values set to unlimited can have the same entity referenced multiple times. This is with using the autocomplete widget and a view that provides a list of current user owned entities. With a list that can get to 100, it makes it hard to know if there are multiples of the same reference.

There needs to be a way to limit it to unique references only.

Comments

kenton.r created an issue. See original summary.

kenton.r’s picture

Component: entity system » entity_reference.module
kenton.r’s picture

I found this post:
https://drupal.stackexchange.com/questions/249618/how-to-prevent-duplica...

I implemented it as a form_alter and it works.

Could we get the autocomplete widget patched with this solution?

navkaur’s picture

Issue tags: +DrupalSouth 2019
joey-santiago’s picture

Assigned: Unassigned » joey-santiago

Starting working on this @Drupal South.

joey-santiago’s picture

Spent some time on this and actually it seems to me that the reference is not added multiple times for the same entity, so i guess the idea should be to filter out the already referenced entity from the autocomplete results?

amateescu’s picture

Category: Bug report » Support request
Status: Active » Fixed

There's a contrib module which covers this functionality: https://www.drupal.org/project/entity_reference_validators

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.