Problem/Motivation

The module currently depends on drupal/select2 and drupal/select_or_other.

  • Select2: The Select2 library relies heavily on older jQuery versions with compatibility issues with jQuery 4. With Drupal 11 and CMS eventually removing jQuery dependencies, select2 is becoming obsolete and problematic for forward compatibility.
  • Select or Other: This module functionality can be efficiently handled by tagify without requiring a separate dependency.

Proposed resolution

Note: wait for issue #3564474: Drupal 11.3: Add void return type to UploadOrLink::submit() for PHP compatibility to be merged or apply its patch.

Replace both dependencies with the Tagify module.

Tagify module added to Drupal CMS and is now the default field widget for certain reference fields.

  • Multi-select: Tagify handles selecting multiple items from a whitelist (replaces select2).
  • Free tagging: Tagify allows creating new tags on the fly, which replicates the "Select or Other" functionality (selecting a value or typing a custom one) in a more unified UI.

Configuration Reference

This patch introduces standardized configuration mapping for the json_form_widget.

1. Default Behavior (Implicit Mapping)

If you provide no ui:options, the module determines the widget usage based on your standard JSON Schema types:

2. Available ui:options (Global)

These options can be applied to almost any field in your ui:options object:

  • "widget": (String) Force a specific widget type (see list below).
  • "title": (String) Override the field label.
  • "description": (String) Override the help text.
  • "placeholder": (String) Grey placeholder text inside the input.
  • "disabled": (Boolean) Make the field read-only (same as Schema readOnly: true).
  • "weight": (Integer) Reorder fields (lower numbers float to top).
  • "hideActions": (Boolean) For Arrays only—removes "Add/Remove" buttons (useful for 1:1 nested forms).

3. Specific Widget Options

When you set a specific "widget", these extra options become available:

Widget Type Option Key Description
tagify
(or select2)
allowCreate (Boolean) Enable "Select or New" mode (Free Tagging).
source (Object) Defines dropdown options.
Example: { "enum": ["A", "B"] }
textarea rows (Integer) Height of the text box.
textFormat (String) Drupal Format ID (e.g., full_html, basic_html).
upload_or_link extensions (String) Allowed file types (e.g., "pdf docx jpg").
progress_indicator (String) "bar" or "throbber".
number step (Number) Stepping interval (e.g., 0.1).
min / max (Number) Constraint limits.
date format (String) PHP Date Format (e.g., "Y-m-d").
datetime timeRequired (Boolean) Force time entry.

4. Auto-Create with Taxonomy

You can also use a Taxonomy vocabulary as the source. When allowCreate is enabled with a taxonomy source, new entries are automatically created as terms in the specified vocabulary.

"brand": {
  "ui:options": {
    "widget": "tagify",
    "allowCreate": true,
    "source": {
      "plugin": "taxonomy",
      "config": {
        "vocabulary": "brands"
      }
    }
  }
}

User interface changes

  • Select2 Fields: Will be rendered as Tagify input fields (visually similar, but more responsive).
  • Select or Other Fields: Instead of a radio button/select box + textfield combo, users will see a single Tagify input to select an existing option or type a new value and press Enter to create it. Default Help Text: Fields with allowCreate: true will automatically display "Select or create a new [label]" as a description if none is provided, improving usability out of the box.

API changes

  • Dependencies:
    • Removed: drupal/select2, drupal/select_or_other
    • Added: drupal/tagify
  • WidgetRouter:
    • getSelectType() now returns select_tagify for select2, autocomplete, and select_other configuration types.
    • getDropdownElement() logic updated to use select_tagify or custom textfield for 'allowCreate'.
    • Removed legacy properties specific to select_or_other (e.g., #other_option).

Remaining tasks

  • [ ] Fix failing tests (Note: Testing environment currently unavailable).
  • [ ] Verify data integrity (ensure values saved by old widgets load correctly in Tagify).
  • [ ] Remove left over references to select2 and select_or_other for compatibility (in new major version?).
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

viappidu created an issue. See original summary.

viappidu’s picture

Issue summary: View changes
StatusFileSize
new7.8 KB

viappidu’s picture

Issue summary: View changes
StatusFileSize
new14.66 KB
new10.5 KB

Fixing issues. Patch from commit.

viappidu’s picture

Issue summary: View changes
viappidu’s picture

Issue summary: View changes
StatusFileSize
new11.3 KB
new22.05 KB
viappidu’s picture

Issue summary: View changes
StatusFileSize
new9.58 KB
new26.57 KB
viappidu’s picture

StatusFileSize
new15.12 KB
new25.99 KB
viappidu’s picture

viappidu’s picture

StatusFileSize
new1.88 KB
new25.82 KB
viappidu’s picture

Included in the "complete" #3565788: Widgets, views support, including changes from #3565343 and #3565448.
Has functionalities on it's own so not closing for the moment

dafeder’s picture

@viappidu I'm very interested in this one, and would like to evaluate and merge this on its own instead of as part of that big MR on 3565788 . Did you address the test failures over there? If so can you port the fixes back to this MR to get it passing? Thanks!

I haven't gotten a chance to test or review closely yet, will do ASAP.

dafeder’s picture

Status: Active » Needs work

Hi, I tried this out and it looks great on the form. However, while it appears to support both selecting existing items and creating new ones in a "free-tagging" setup, the items are not present after saving the form. This is true whether I pick an existing item from the list or create a new one. I suspect this is related to tagify generally expecting to work with references to entities like taxonomy terms, but here (in my use case anyway, within DKAN) we just want to add new items to an array of strings. Perhaps something needs to change in the ValueHandler.

If you want to recreate in whatever your project looks like, without installing DKAN, you could build a form around the main JSON schema from DKAN:

https://github.com/GetDKAN/dkan/blob/2.x/schema/collections/dataset.json

dafeder’s picture

Just to update - we're going to keep this issue open, and try to bring this in. The problem is tagify is very closely coupled to the Drupal core autocomplete API, and wants to create a new entity immediately as I understand it. The way this was previously implemented in the DKAN version of JSON Form Widget, it would use the source plugin to populate the list of existing terms available to select2, but any new items created were simply added to the array of strings submitted with the form. DKAN was then handling the mapping to existing referenced entities or creating new ones as needed.

I think this more Drupal-standard approach makes a lot more sense for a general-purpose module. Probably even for DKAN long-term, but in the short term it would difficult to change the DKAN workflow to support this, and possibly very disruptive for existing sites. I'm going to try over the next week or so to think of a reasonable way to support select2 as a legacy widget type while still incorporating this as the default autocomplete widget.

viappidu’s picture

DKAN was then handling the mapping to existing referenced entities or creating new ones as needed.

You mean using entity reference other than taxonomy terms to fill a list of options?
(If not for fails or omissions in my code) that is what views (entity reference display) is there for. To be honest in my case the view reference was to get the options values, i do not remember testing with creating a new entity, I think so but not sure. That would be interesting and not too hard to add if not already there.

It does already work for taxonomy terms, not sure if I set that as "optional" or not. Meaning I do not remember if it always add a new term or if there is an option to let the user decide if or not. *Does it validate options or simply add it? :)