#states disable property has stopped working for submit button and other elements

Created on 19 April 2023, about 1 year ago
Updated 5 June 2024, 11 days ago

Problem/Motivation

๐Ÿ› #states cannot check/uncheck checkboxes elements Fixed included a change to no longer set the disabled property of the targeted element directly, since it should be included by .closest('.js-*').find() (which will target both individual elements or groups with the same code).

However, the find() doesn't include all the HTML elements that can have the disabled attribute applied (https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/disabled#ov...)

Steps to reproduce

Create a form with a button element, and a #states rule which changes its disabled status. This problem can be seen with the submit button; example:

$form['actions']['submit'] = [ 
  '#type' => 'submit',
  '#value' => $this->t('Submit'),
  '#states' => [
    'disabled' => [':input[name="allow_overwrite"]' => ['checked' => FALSE]],
  ],  
];

Proposed resolution

Before change:

    if (e.trigger) {
      $(e.target)
        .closest('.js-form-item, .js-form-submit, .js-form-wrapper')
        .toggleClass('form-disabled', e.value)
        .find('select, input, textarea')
        .prop('disabled', e.value);
    }

Add additional HTML elements to the find() parameter: button, fieldset, optgroup, option.

After change:

    const tagsSupportDisable =
      'button, fieldset, optgroup, option, select, textarea, input';
    if (e.trigger) {
      $(e.target)
        .closest('.js-form-item, .js-form-submit, .js-form-wrapper')
        .toggleClass('form-disabled', e.value)
        .find(tagsSupportDisable)
        .addBack(tagsSupportDisable)
        .prop('disabled', e.value);
    }

Remaining tasks

User interface changes

None.

API changes

disabled property works again.

Data model changes

None.

Release notes snippet

๐Ÿ› Bug report
Status

Fixed

Version

10.2 โœจ

Component
Formย  โ†’

Last updated 1 day ago

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada gapple

Live updates comments and jobs are added and updated live.
  • JavaScript

    Affects the content, performance, or handling of Javascript.

Sign in to follow issues

Merge Requests

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.69.0 2024