- πΊπΈUnited States froboy Chicago, IL
I've confirmed this issue as stated in #2988400-12: Chosen library and settings are not attached if preRender is not called β .
In some situations, if Drupal's render pipeline does not know about an element that Chosen has a callback for (currently select, date combo, or select other), then the Chosen library and settings are not attached.
Some possible scenarios:
- An element is written directly into a twig file
- An element is loaded by external JS (via an embed)Additionally if the Chosen JS library is loaded by a custom theme, this can result in cases where the JS is loaded but the settings are not passed to drupalSettings, so all
select:visible
elements have Chosen applied instead of the elements selected in the "Apply Chosen to the following elements" field.Possible resolutions:
1. #2988400-12: Chosen library and settings are not attached if preRender is not called β - call
chosen_attach_library
directly where you need it in your theme, block, etc. (This could be added to the docs somewhere.) A brute force approach might look like this:function my_theme_preprocess_html(&$variables) { ... chosen_attach_library($variables['page']); ... }
2. Update the "Use chosen for admin pages and/or front end pages" field
- Change the existing options to read like "Include Chosen on every page that contains elements it can act on".
- Add a new option: "Include Chosen on every page (even if Drupal doesn't know about elements Chose can act on)"