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

CommentFileSizeAuthor
#2 states_bug_demo.tgz2.65 KBrfay
#1 drupal.states-item.1.patch1.72 KBsun
Support from Acquia helps fund testing for Drupal Acquia logo

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

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.

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

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

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

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

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

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

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

akalam’s picture

Issue summary: View changes

#states currently works fine with #type => 'item' on D8. Tested on 8.5.
Can someone test it on D7?

akalam’s picture

Version: 8.6.x-dev » 7.x-dev
init90’s picture

Status: Needs work » Fixed

For Drupal 7 it's also works. Based on that fact I'm closing the issue.

The only point that is not resolved concerns the comment from @Jelle_S, the refreshing of the documentation for #states and #markup, but it is probably better to do in the new issue.

Status: Fixed » Closed (fixed)

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