Chosen works wonderfully. The only issue I have run into is that the module ignores initially hidden fields. These tend to be field hidden and loaded conditionally by ajax.

<?php
/* Class hidden is set to display:none */
$form['my_field']['#attributes']['class'][] = 'hidden';
 
$form['my_field']['#states'] = array(
  'visible' => array(
    '#edit-field-dependent-und' => array('value' => 'SomeValue'),
  ),
);
?>

The above will correctly hide the field initially and display via drupals FAPI states, but Chosen will not apply itself to the field.

Comments

JMOmandown’s picture

Upon reading further in the Issue queue the following is most likely related: https://drupal.org/node/2104875

Dave Reid’s picture

Issue summary: View changes
Status: Active » Fixed

No, the Drupal AJAX system is different from the JS states system. Your best bet is to manually include a selector that would match this field, even when hidden, on the settings form's "Apply Chosen to the following elements". Otherwise you'd need to change the default selector from 'select:visible' to just 'select'.

hass’s picture

I had a case opened somewhere and it should be select.chosen or so... That is a bug of the module :-)

Dave Reid’s picture

Another good solution would be #2210767: Add 'chosen-enable' and 'chosen-disable' classes along with corresponding FAPI property which would only require you to add '#chosen' => TRUE to your select box.

Status: Fixed » Closed (fixed)

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