I have a Drupal 9 installation running Commerce 2. My products use a taxonomy entity reference field (tag style). There's one products category, where I need to have more references in the tag input field than currently allowed (1024 characters).

I looked it up and found a similar post where someone suggested to write a module to increase the maximum input value like so:

function MODULE_field_widget_form_alter(&$element, &$form_state, $context) {

  if ($context['widget']->getPluginId() == 'entity_reference_autocomplete_tags') {
    if ($element['target_id']['#maxlength'] == 1024) {
      $element['target_id']['#maxlength'] = 3072;

So I did that, but it still doesn't let me input more than 1024 characters. Any help would be appreciated. Thank you!

  • You may want to look at changing that field to a select list and using something like Chosen to emulate an autocomplete experience. Even if you can add more tags into the autocomplete field, it's going to be a bad experience for editors. – sonfd Feb 21 at 17:39
  • @sonfd Yeah, I thought about that too. But sorrily this field references to a list of taxonomy terms which holds like 500+ values. So it will be a pain to edit it anyways :( – Berry Dingle Feb 21 at 18:04

I didn't manage to increase the maxlength of the input, but installed "Autocomplete deluxe" module, which implements the widget input field via jQuery chosen. Now I can set as many values as I like.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.