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.
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
Comment #1
JMOmandown CreditAttribution: JMOmandown commentedUpon reading further in the Issue queue the following is most likely related: https://drupal.org/node/2104875
Comment #2
Dave ReidNo, 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'.
Comment #3
hass CreditAttribution: hass commentedI had a case opened somewhere and it should be select.chosen or so... That is a bug of the module :-)
Comment #4
Dave ReidAnother 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.