The States API does not execute condition at first display when no default value is setted in field and select field has option #multiple = TRUE or #size.
Steps to reproduce:
- Create two fields in a form with the following code:
$form['dependee'] = array(
'#type' => 'select',
'#options' => array(
'a' => 'Option A',
'b' => 'Option B',
'c' => 'Option C',
),
'#size' => 3,
);
$form['dependent'] = array(
'#type' => 'textfield',
'#states' => array(
'visible' => array(
'select[name="dependee"]' => array('value' => array('a')),
),
),
);
I try to fix this adding $this->reevaluate() at the end of states.Dependent.prototype.initializeDependee. This works in browser, but writing tests with mink fail.
Tests should be covered by #2702233: [backport] Add JavaScript tests for Form API #states: required, visible, invisible, expanded, checked, unchecked and this issue has been found working on #1149078: States API doesn't work with multiple select fields
Comments
Comment #10
dwwThis came up as a random bugsmash target. Given the title, the complexity of #states, and its track record of needing a lot of work to get right, I'm guessing this is still a real bug. I haven't actually tried to reproduce it yet.
Re: Needs tests, see
core/tests/Drupal/FunctionalJavascriptTests/Core/Form/JavascriptStatesTest.phpwhich now exists.