Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#2 | states_bug_demo.tgz | 2.65 KB | rfay |
#1 | drupal.states-item.1.patch | 1.72 KB | sun |
Comments
Comment #1
sunOf course, we cannot support plain #markup elements.
But attached patch makes #type item work.
Comment #2
rfayThis 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".
Comment #3
webchickThis looks like a sensible clean-up.
Committed to HEAD!
Comment #4
rfayNice work fixing up all these #states issues, sun!
sun++
Comment #6
Jelle_SMaybe 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...
Comment #7
rafamd CreditAttribution: rafamd commentedTagging 'documentation'
Comment #8
sunComment #19
akalam CreditAttribution: akalam at Metadrop commented#states currently works fine with #type => 'item' on D8. Tested on 8.5.
Can someone test it on D7?
Comment #20
akalam CreditAttribution: akalam at Metadrop commentedComment #21
init90For 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.