State event handler, for Chosen update, not triggered

Created on 13 August 2025, 25 days ago
Updated 24 August 2025, 13 days ago

Problem/Motivation

The event handler listening for state:disabled never gets triggered.

Steps to reproduce

Create a simple form with a checkbox and a Chosen select whose enabled states depends on the checkbox.

$form['enabler'] = [
    '#type' => 'checkbox',
    '#title' => 'Enable',
];

$form['selecter'] = [
    '#type' => 'select',
    '#title' => 'Select',
    '#chosen' => TRUE,
    '#options' => [
        'foo' => 'Foo',
    ],
    '#empty_option' => '- Empty -',
    '#states' => [
        'enabled' => [
            ':input[name="enabler"]' => ['checked' => TRUE],
        ],
    ],
];

While the actual select element gets its disabled attribute toggled by the checkbox, the Chosen select starts out and always remains enabled.

Proposed resolution

The states events are triggered via jQuery (both in 10.5.x and in 11.x). jQuery only calls jQuery event handlers and native event handlers specified through the onevent attributes (both in 3.7.1 and 4.0.0-rc.1). As this module's event handler is added through the native addEventHandler method as of 5.0.2, it never gets called by jQuery.

My proposed solution is to add back to jQuery dependency and listen for state:disabled with a jQuery event listener.

Remaining tasks

Maybe there is a way to dynamically detect when #states or jQuery is used, and only add the event listener in that case.

User interface changes

None.

API changes

None.

Data model changes

None.

🐛 Bug report
Status

Active

Version

5.0

Component

Code

Created by

🇦🇹Austria castanearie

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024