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
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 commentedTagging 'documentation'
Comment #8
sunComment #19
akalam commented#states currently works fine with #type => 'item' on D8. Tested on 8.5.
Can someone test it on D7?
Comment #20
akalam 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.