The following code hides the the checkbox but not the markup item:

  $form['test_options'] = array(
    '#type' => 'select',
    '#title' => t('Template'),
    '#options' => drupal_map_assoc(array(t('Default'), t('Template 1'), t('Template 2'))),
  );
  $form['copy'] = array(
    '#type' => 'checkbox',
    '#title' => t('Send me a copy.'),
    '#states' => array(
      'visible' => array( 
        ':input[name=template_options]' => array('value' => t('Default')),
      ),
    ),
  );
  $form['t1_info'] = array(
    '#type' => 'item',
    '#markup' => t('Info for Template 1'),
    '#states' => array(
      'visible' => array(
        ':input[name=template_options]' => array('value' => t('Default')),
      ),
    ),
  );

Ben

Files: 
CommentFileSizeAuthor
#2 states_bug_demo.tgz2.65 KBrfay
#1 drupal.states-item.1.patch1.72 KBsun
PASSED: [[SimpleTest]]: [MySQL] 20,078 pass(es). View

Comments

sun’s picture

Title: #states doen't hide markup item » #states doesn't work for #type item
Version: 7.0-alpha4 » 7.x-dev
Assigned: Unassigned » sun
Status: Active » Needs review
FileSize
1.72 KB
PASSED: [[SimpleTest]]: [MySQL] 20,078 pass(es). View

Of course, we cannot support plain #markup elements.

But attached patch makes #type item work.

rfay’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
2.65 KB

This works fine and looks like a code cleanup at the same time. I think it's RTBC.

Attached is a module to test it with. Click on the menu item "Bug Demo: #states working with #type = item".

webchick’s picture

Status: Reviewed & tested by the community » Fixed

This looks like a sensible clean-up.

Committed to HEAD!

rfay’s picture

Nice work fixing up all these #states issues, sun!

sun++

Status: Fixed » Closed (fixed)

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

Jelle_S’s picture

Status: Closed (fixed) » Needs work

Of course, we cannot support plain #markup elements.

Maybe it should be documented in the form api that #states does not work for elements of type 'markup'.
Currently the form api says that #states can be used by 'any element':
http://api.drupal.org/api/drupal/developer!topics!forms_api_reference.ht...

rafamd’s picture

Category: bug » task
Issue tags: -FAPI #states

Tagging 'documentation'

sun’s picture

Version: 7.x-dev » 8.x-dev
Assigned: sun » Unassigned
Issue tags: +FAPI #states

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • webchick committed 1f3e11d on 8.3.x
    #783438 by sun: Fixed #states doesn't work for #type item.
    
    

  • webchick committed 1f3e11d on 8.3.x
    #783438 by sun: Fixed #states doesn't work for #type item.
    
    

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

  • webchick committed 1f3e11d on 8.4.x
    #783438 by sun: Fixed #states doesn't work for #type item.
    
    

  • webchick committed 1f3e11d on 8.4.x
    #783438 by sun: Fixed #states doesn't work for #type item.
    
    

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.