Problems limiting cardinality in entity_autocomplete_tagify element

Created on 24 June 2025, 14 days ago

Problem/Motivation

I found it very difficult to figure out how to limit the cardinality in an 'entity_autocomplete_tagify' element in a form.

The correct solution is:

    $form['selection']['select'] = [
      '#type' => 'entity_autocomplete_tagify',
      '#target_type' => 'node',
      '#cardinality' => 1,
      '#identifier' => 'some_id',
      '#attributes' => ['class' => 'some_id']
    ];

The docs for this element seem flawed, and the code could probably support this use case better.

(1) There's no mention of the '#cardinality' property in the docs.

(2) The docs mention the '#tags' property that may not exist.

(3) The docs say the identifier is optional, but it's not if #cardinality > 0.

(4) The docs don't explain the identifer has to be set as a class or id.

(5) Could we provide a default identifier on the element if none is specified? e.g. give a random string identifer of the form tagifier_id_j65b5b and set that as a class on the element?

Proposed resolution

Fix the docs, provide better validation or defaults in the element to prevent javascript errors.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

1.2

Component

Code

Created by

🇬🇧United Kingdom jonathanshaw Stroud, UK

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

Comments & Activities

Production build 0.71.5 2024