Problem/Motivation
States API collapsed/open/closed state doesn't work for <details>.
The state API uses still '> summary a' to change the state of an an element.
Just make a form:
$form['student_type'] = array(
'#type' => 'radios',
'#options' => array(
'high_school' => t('High School'),
'undergraduate' => t('Undergraduate'),
'graduate' => t('Graduate'),
),
'#title' => t('What type of student are you?'),
);
$form['name'] = array(
'#type' => 'details',
'#title' => t('Name'),
'#collapsible' => TRUE, // Added
'#open' => FALSE, // Added
'#states' => array(
'open' => array(
':input[name="student_type"]' => array('value' => 'high_school'),
),
),
);
// To make these fields required
$form['name']['first'] = array(
'#type' => 'textfield',
'#title' => t('First name'),
'#required' => TRUE, // Added
);
$form['name']['last'] = array(
'#type' => 'textfield',
'#title' => t('Last name'),
'#required' => TRUE, // Added
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Submit',
);
return $form;
name should be open if high_school is selected.
Proposed resolution
Change the selector in 'state:collapsed'-event from '> summary a' to '> summary'
| Comment | File | Size | Author |
|---|---|---|---|
| drupal_state-api-collapsed-fix.patch | 421 bytes | eyilmaz |
Comments
Comment #2
eyilmazComment #3
eyilmazComment #4
eyilmazComment #5
eyilmazComment #6
droplet commentedCorrect. We've updated collapse.js in D8
Comment #7
jcnventuraSome info was hidden due to missing code tags.
Comment #9
eyilmazlatest test was aborted for some reason.
Comment #11
droplet commentedComment #13
eyilmazComment #15
eyilmazComment #16
alexpottComment #17
alexpottLooking at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/details I think this fix is valid. I wish we had front end testing.
Committed b9b16f7 and pushed to 8.0.x and 8.1.x. Thanks!