Problem/Motivation

If I use "Autocomplete (Tags with selectize.js)" on:

Entity reference (Taxonomy Term) field
"Create referenced entities if they don't already exist" enabled
One vocabulary selected

selectize works perfectly UNLESS I 'Add' a term that matches one that already exists within another vocabulary .

Then if I try and save the node it then fails with an error :

This entity (taxonomy_term: 124) cannot be referenced.

Where term 124 is the matching term in the other vocabulary. (Not the vocabulary set for the field).

Comments

mistergroove created an issue. See original summary.

mistergroove’s picture

Comparing validateEntityAutocomplete in Drupal\Core\Entity\Element\EntityAutocomplete and Drupal\selectize\Element\SelectizeEntityAutocomplete it seems the issue is the options are set differently now :

$options = $element['#selection_settings'] + [
  'target_type' => $element['#target_type'],
  'handler' => $element['#selection_handler'],
];

Drupal\Core\Entity\Element\EntityAutocomplete

$options = [
  'target_type' => $element['#target_type'],
  'handler' => $element['#selection_handler'],
  'handler_settings' => $element['#selection_settings'],
];

Drupal\selectize\Element\SelectizeEntityAutocomplete

Changing it the selectize one to match seems to solve the issue.

mistergroove’s picture

I've made a patch which addresses this issue and the drag and drop issue in https://www.drupal.org/project/selectize/issues/3458652 for testing.