(written by Grok and reviewed by Max Milbers)
Audience: Anyone with a <select> in admin or shop that used Chosen
Library: Choices.js (Joomla web asset on J4+; VM wrapper module)
Related: VM Init Registry
1. Why Chosen went away
Chosen was jQuery. It aged. Joomla 4/5 already ships Choices. VirtueMart 5 wraps it so searchable dropdowns survive tabs, AJAX, and Alpine show/hide.
VirtueMart’s answer: one module, vmchoices.module.js. You mark selects. Core inits them. After AJAX you fire one event.
2. Which selects
| Context | Selector |
|---|---|
| Shop frontend | select.vm-chzn-select (the old Chosen class still works as the opt-in) |
| Administrator | almost every select, except .vm-chzn-add and language switchers |
Init skips nodes inside display:none (Choices measures width at init; a hidden pane produces a dead control). When a tab becomes visible, re-init.
3. After AJAX or a tab
document.dispatchEvent(new Event('vmReinitChoices'));
Core tabs already do this on activeTab. Plugin-parameter forms that inject HTML do the same. You do not destroy and recreate by hand unless you own the instance.
4. Quick start
- Output a normal
<select>. In FE add classvm-chzn-selectif you want Choices. - Do not load Chosen.
- After you inject markup, dispatch
vmReinitChoicesor rely onVMInitreInit. - To keep a native select (e.g. a tiny filter), add
vm-chzn-addin admin.
5. Do’s and don’ts
- Do not init Choices on a select that is still
display:none. - Do not copy width from Choices onto a cloned search input (core CSS already hides that 1px trick except when the list is open).
- Do not assume
this.valueis current onchangefor a single select — listen to ChoicesaddItemif you must. Multiple selects: do not assignel.value = vor you drop the other options. - Do not load a second Choices from a CDN.
6. Paths
media/com_virtuemart/js/choices/vmchoices.module.js- Event:
vmReinitChoices