Install
Works with Drupal: ^11 || ^12Using 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
#statestriggers (#3627946). Core'sstates.jsfinds 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'sform_controls, and map its own events to native ones inevents, such ascw-change: change. For the listed controls,:inputmatches 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
#statesdependents (#3627946).disabled,readonly,requiredandcheckedare set on a listed control that carries#states.disabled,readonlyandcheckedare 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. Settingcheckedfires a nativechange, so states that depend on it follow.visiblealready 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 indrupalSettings.webComponentRuntime.formControlsandevents, keyed by library ID.
Upgrading
- Libraries opt in. A registry file without
form_controlsgets 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. :inputchanges page-wide while a library lists form controls. In core, that affectsstates.jsand how jQuery Form collects fields that sit outside their form and name it in theirformattribute. A listed control placed outside its form that way is now serialized in an AJAX submission, through itsnameandvalueproperties.- An
html_tagelement with#statesof its own doesn't get them: core processes#statesafter#pre_render, wherehtml_taghas already built its markup. Put the states on a wrapper, or callFormHelper::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.