Allow #states property to accept TRUE as a condition

Created on 24 January 2013, about 12 years ago
Updated 21 September 2024, 6 months ago

Problem/Motivation

Sometimes it is desirable to trigger a form element state on the existence of Javascript, rather than on the state of another form element. For instance, I may have a form element that is hidden by default, but displays if Javascript is enabled on a page. Currently this is only possible through custom Javascript, or kludgy workarounds.

Proposed resolution

Allow #states to accept TRUE as a valid condition, as shown in this example:

$form['options']['published_date_override_container'] = array(
  '#type' => 'container',
  '#attributes' => array(
    // Hide this container by default.
    'class' => array('element-hidden'),
  ),
  '#states' => array(
    // Show this container if Javascript is enabled.
    'visible' =>  TRUE,
  ),
);

Remaining tasks

Implement proposed resolution.

User interface changes

None.

API changes

TRUE will be a valid condition for the #states property on form elements.

✨ Feature request
Status

Closed: works as designed

Version

11.0 πŸ”₯

Component
FormΒ  β†’

Last updated 26 minutes ago

Created by

πŸ‡ΊπŸ‡ΈUnited States jstoller

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024