/** * Tom Select integration. * * Replaces Select2. Tom Select is vanilla JS and exposes its instance on the * element as `el.tomselect`, so nothing here needs jQuery. * * Select2 concepts and their equivalents, for anyone reading this later: * $(el).select2({tags:true}) -> create: true * $(el).val(null).trigger('change') -> el.tomselect.clear() * $(el).trigger('change.select2') -> el.tomselect.sync() (options replaced) * $(el).on('select2:select', fn) -> el.tomselect.on('change', fn) * * WHY THIS IS ITS OWN FILE RATHER THAN PART OF js/app.js * * The visible flash on page load was a timing problem, not a styling one. The * browser paints the native leaves a sibling *
behind it. That means a * querySelectorAll('.select2') run AFTER any enhancement matches the * wrapper too, and the wrapper has no .tomselect of its own so the guard * above waves it through. Constructing Tom Select on a
yields a * second, empty control - no options, no placeholder - stacked on top of * the working one, which reads as "the select is blank". * * The sweeps below and in js/app.js are scoped to `select.select2` so this * cannot happen, but the check belongs here as well: initTomSelect is * called directly from agent/js/share_modal.js and anywhere else that * grows a call site later. */ if (el.tagName !== 'SELECT' && el.tagName !== 'INPUT') { return null; } var settings = Object.assign({ create: false, allowEmptyOption: true, plugins: el.multiple ? ['remove_button'] : [], placeholder: el.getAttribute('data-placeholder') || undefined }, options || {}); return new TomSelect(el, settings); } /** Re-read the