Install

Works with Drupal: ^11 || ^12

Using Composer to manage Drupal site dependencies

Alternative installation files

Download tar.gz 102.16 KB
MD5: ab1ea6e3af2b8fca0683bb23cc637d19
SHA-1: 7f1fbeccefe7a194b479713e988a74ed3e5d8d09
SHA-256: 01e4ca912369fe39535c6c7135c816190335057447a0fe0b51c253aae1cd6625
Download zip 201.15 KB
MD5: 801765e033c49405830cca4ef31ebc09
SHA-1: a0ebe64808c05102a31757ed355bb1c92ea52fd1
SHA-256: 0f47bc69d745d5e25e6a537ac669e8eb3017b7aeaacd0ae1d2e39f1b79afaa30

Release notes

1.4.0 makes core's #states work with a library's web component form controls. A control can be the trigger in a condition, and it can take dependent states such as disabled, read-only, required and checked, just like a native form element. A library opts in by listing its controls and events in its registry file. Libraries that don't list any work as before.

New features

  • Form controls as #states triggers (#3627946). Core's states.js finds triggers with jQuery's :input, which matches only native tags. It also listens for native events, which a control's inner input fires inside the shadow root, where they never reach the control. A library can now list its form-control tags in the registry file's form_controls, and map its own events to native ones in events, such as cw-change: change. For the listed controls, :input matches them, so conditions written the usual way, ':input[name="toggle"]' => ['checked' => TRUE], find them. Each of the library's events also fires its native event on the control, after the library's own listeners have run. A library that already fires the native event itself isn't doubled.
  • Form controls as #states dependents (#3627946). disabled, readonly, required and checked are set on a listed control that carries #states. disabled, readonly and checked are also set on the listed controls inside the form item or wrapper a state applies to, as core does for native elements. If the control has the property, it's set; otherwise the attribute is, and the control reads it once it upgrades. Setting checked fires a native change, so states that depend on it follow. visible already worked, since core toggles the wrapper.
  • AJAX (#3627946). The script, web_component_runtime/form-controls, is attached wherever such a library is on the page, AJAX responses included. Each library's lists come in drupalSettings.webComponentRuntime.formControls and events, keyed by library ID.

Upgrading

  • Libraries opt in. A registry file without form_controls gets nothing new on its pages. Both keys were already part of schema 1, so registry files don't change shape. A library that relies on them should require Web Component Runtime 1.4 or later, since earlier releases accept the keys but ignore them.
  • :input changes page-wide while a library lists form controls. In core, that affects states.js and how jQuery Form collects fields that sit outside their form and name it in their form attribute. A listed control placed outside its form that way is now serialized in an AJAX submission, through its name and value properties.
  • An html_tag element with #states of its own doesn't get them: core processes #states after #pre_render, where html_tag has already built its markup. Put the states on a wrapper, or call FormHelper::processStates() on the element before it renders.

Requirements

Drupal 11 or 12, with no new dependencies.

See the README's "Form controls and #states" section for details.

Created by: matthand
Created on: 1 Dec 2026 at 12:27 UTC
Last updated: 1 Dec 2026 at 12:27 UTC
New features
Unsupported

Other releases