select2_box(), chosen_box() form()

A searchable select on jQuery: Select2 3.5 (select2_box()) or Chosen 1.7 (chosen_box()); new code uses tom_select_box().

form()->select2_box($name, $values = null, $extra = [], $replace = [])
form()->chosen_box($name, $values, $extra = [], $replace = [])

Options

OptionMeaning
$valuesValue => text (or groups).
multipleSeveral values (name[]).
js_optionsOptions of the plugin (['width' => '300px', 'allowClear' => 'true']).
selected, placeholder, disabledAs for select_box().

Example

Code

$cities = ['kyiv' => 'Kyiv', 'lviv' => 'Lviv', 'odesa' => 'Odesa', 'kharkiv' => 'Kharkiv'];
return form(['city' => 'lviv', 'city2' => 'odesa'])
    ->select2_box('city', $cities, ['js_options' => ['width' => '300px']])
    ->chosen_box('city2', $cities, ['desc' => 'City (Chosen)']);

Notes

  • Both need jQuery and load their asset with the field. Pure additions since 2026 keep their output; tom_select_box() needs no jQuery and works on htmx swaps.

See also: form/tom_select_box, html/select2_box, demo:form/jquery_widgets