Issue #3347144 by dgtlmoon, mstrelan, Evaldas Užkuras, bkosborne, FeyP, pirvudoru: Form API #states property/states should use .once() to apply its rules (Can cause failures with BigPipe and possibly other situations)
parent
e6304cd961
commit
d6b6ad8fd6
|
@ -93,15 +93,16 @@
|
||||||
*/
|
*/
|
||||||
Drupal.behaviors.states = {
|
Drupal.behaviors.states = {
|
||||||
attach(context, settings) {
|
attach(context, settings) {
|
||||||
const $states = $(context).find('[data-drupal-states]');
|
const elements = once('states', '[data-drupal-states]', context);
|
||||||
const il = $states.length;
|
const il = elements.length;
|
||||||
|
|
||||||
for (let i = 0; i < il; i++) {
|
for (let i = 0; i < il; i++) {
|
||||||
const config = JSON.parse(
|
const config = JSON.parse(
|
||||||
$states[i].getAttribute('data-drupal-states'),
|
elements[i].getAttribute('data-drupal-states'),
|
||||||
);
|
);
|
||||||
Object.keys(config || {}).forEach((state) => {
|
Object.keys(config || {}).forEach((state) => {
|
||||||
new states.Dependent({
|
new states.Dependent({
|
||||||
element: $($states[i]),
|
element: $(elements[i]),
|
||||||
state: states.State.sanitize(state),
|
state: states.State.sanitize(state),
|
||||||
constraints: config[state],
|
constraints: config[state],
|
||||||
});
|
});
|
||||||
|
@ -120,7 +121,7 @@
|
||||||
*
|
*
|
||||||
* @constructor Drupal.states.Dependent
|
* @constructor Drupal.states.Dependent
|
||||||
*
|
*
|
||||||
* @param {object} args
|
* @param {{state: Drupal.states.state, constraints: *, element: (*|jQuery|HTMLElement)}} args
|
||||||
* Object with the following keys (all of which are required)
|
* Object with the following keys (all of which are required)
|
||||||
* @param {jQuery} args.element
|
* @param {jQuery} args.element
|
||||||
* A jQuery object of the dependent element
|
* A jQuery object of the dependent element
|
||||||
|
|
|
@ -27,7 +27,7 @@ class JavascriptStatesTest extends WebDriverTestBase {
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
protected static $modules = ['form_test'];
|
protected static $modules = ['form_test', 'big_pipe'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
|
|
Loading…
Reference in New Issue