Was making a form today and using the states api to hide a few fields when I found out that my select or other field wasn't being hidden. (states api).

Simple example form

  $form["checkbox"] = array(
    '#title' => 'Check me',
    '#type' => 'checkbox',
    '#default_value' => FALSE,
  );
  $form["selectother"] = array(
    '#type' => 'select_or_other',
    '#title' => 'Select or Other',
    '#default_value' => 1,
    '#options' => array(1 => 'First', 2 => 'Second', 3 => 'Third'),
    '#multiple' => FALSE,
    '#other' => t(' - Other - '),
    '#other_delimiter' => FALSE,    
    '#other_unknown_defaults' => 'other',
    '#states' => array(
      'visible' => array(
        "#edit-checkbox" => array('checked' => TRUE),
      ),
    ),       
  );   
  $form["select"] = array(
    '#type' => 'select',
    '#title' => 'Select',
    '#default_value' => 1,
    '#options' => array(1 => 'First', 2 => 'Second', 3 => 'Third'),
    '#multiple' => FALSE,
    '#states' => array(
      'visible' => array(
        "#edit-checkbox" => array('checked' => TRUE),
      ),
    ),       
  );   

Comments

legolasbo’s picture

Status: Active » Closed (duplicate)
Related issues: +#1335568: #ajax callback not firing on Select (or other) field

https://www.drupal.org/node/1335568#comment-9452977 should guide you in the right direction.

ctrladel’s picture

Confirming that adding select before the states attribute fixed everything. Am I crazy or is this not documented anywhere?

the working field code

  $form["selectother"] = array(
    '#type' => 'select_or_other',
    '#title' => 'Select or Other',
    '#default_value' => 1,
    '#options' => array(1 => 'First', 2 => 'Second', 3 => 'Third'),
    '#multiple' => FALSE,
    '#other' => t(' - Other - '),
    '#other_delimiter' => FALSE,    
    '#other_unknown_defaults' => 'other',
    '#select_states' => array(
      'visible' => array(
        "#edit-checkbox" => array('checked' => TRUE),
      ),
    ),       
  );  
legolasbo’s picture

You are not crazy, it isn't documented anywhere. I've just started maintaining this module after a year of inactivity by the previous maintainer(s). My current focus is on fixing bugs and writing tests. Any help with documenting current behaviours would be greatly appreciated.

Also '#other_delimiter' => FALSE, should not do anything at the moment and I don't think it ever will in the future.