value [optional]. * * @return void */ public static function chosen($selector = '.btn-toolbar', $debug = null, $options = array()) { static $loaded = 0; // register only once if ($loaded) { return; } $loaded = 1; $version = new JVersion(); /** * Use select2 rendering only in case of WordPress 5.2 or lower. * Starting from WordPress 5.3 the dropdowns are rendered properly * and there is no need to use a different layout. * Contrarily, we will lose the possibility of searching the options. * * @since 10.1.30 */ // $use_select2 = version_compare($version->getShortVersion(), '5.3', '<') ? 1 : 0; $use_select2 = 0; // load always select2 plugin // JHtml::fetch('select2'); JText::script('JGLOBAL_SELECT_AN_OPTION'); // add support for chosen plugin JFactory::getDocument()->addScriptDeclaration( << 0) { data.allowClear = false; data.placeholder = null; } // turn off search when there are 5 options or less if (jQuery(this).find('option').length <= 5) { data.minimumResultsForSearch = -1; } // init select2 plugin jQuery(this).select2(data); } }); return this; } } jQuery(document).ready(function() { jQuery('{$selector}') .find('select') .chosen() .on('chosen:updated', function() { // refresh select2 value when triggered // jQuery(this).select2('val', jQuery(this).val()); }); }); JS ); } }