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'

CommentFileSizeAuthor
drupal_state-api-collapsed-fix.patch421 byteseyilmaz

Comments

eyilmaz created an issue. See original summary.

eyilmaz’s picture

Issue summary: View changes
eyilmaz’s picture

Issue summary: View changes
eyilmaz’s picture

Issue summary: View changes
eyilmaz’s picture

Issue summary: View changes
droplet’s picture

Status: Active » Reviewed & tested by the community

Correct. We've updated collapse.js in D8

jcnventura’s picture

Issue summary: View changes

Some info was hidden due to missing code tags.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, drupal_state-api-collapsed-fix.patch, failed testing.

eyilmaz’s picture

Status: Needs work » Reviewed & tested by the community

latest test was aborted for some reason.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, drupal_state-api-collapsed-fix.patch, failed testing.

droplet’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, drupal_state-api-collapsed-fix.patch, failed testing.

eyilmaz’s picture

Status: Needs work » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, drupal_state-api-collapsed-fix.patch, failed testing.

eyilmaz’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Issue tags: +JavaScript
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Looking 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!

  • alexpott committed cba756a on 8.1.x
    Issue #2584869 by eyilmaz: States collapsed/open/closed doesn't work for...

  • alexpott committed b9b16f7 on
    Issue #2584869 by eyilmaz: States collapsed/open/closed doesn't work for...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.