Chosen currently activates on page load, and replaces normal select boxes with Chosen select boxes.

However, I have a custom form with an 'add more' button. When you click on the 'add more' button, it adds another fieldset via AJAX. The problem is, on these AJAX-appened form elements, you won't have Chosen formatting, because Chosen only does the replacement on page load.

Is there a way to trigger Chosen to also replace the select boxes on the AJAX-appended content?

Comments

Dave Reid’s picture

Issue summary: View changes
Status: Active » Postponed (maintainer needs more info)

Chosen uses Drupal.behaviors and attach which means it should work out of the box with anything loaded via Drupal core's native AJAX API. Is it not actually working? Which version of the Chosen module and library are you using?

micromegas’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

Back in October, I had to use

$element = array(
  ...
  ...
  '#attributes' => array(
    'class' => array('chosen-widget'),
  ),
);

in order to get Chosen to work after an AJAX call.

Now, going back and re-testing using the latest versions of the Chosen module and library, it is working correctly.