public function chosen_box()
{
return _class('html')->chosen_box('input_name', ['k1' => 'key1', 'k2' => 'key2']);
}
public function chosen_box($name, $values = [], $selected = '', $extra = [])
{
if (is_array($name)) {
$extra = (array) $extra + $name;
} else {
$extra['name'] = $name;
}
$extra['force_id'] = $extra['force_id'] ?: __FUNCTION__ . '_' . ++$this->_ids[__FUNCTION__];
asset('chosen');
$js_options = (array) $extra['js_options'] + [
'disable_search_threshold' => 10,
'no_results_text' => t('No results match'),
'placeholder_text_multiple' => t('Select Some Options'),
'placeholder_text_single' => t('Select an Option'),
'search_contains' => true,
// put default js options here
];
jquery('$("#' . addslashes($extra['force_id']) . '").chosen(' . json_encode($js_options, JSON_PRETTY_PRINT) . ');');
$func = $extra['multiple'] ? 'multi_select' : 'select_box';
return $this->$func($extra, $values, $selected);
}