Dropdown

Custom select dropdown with keyboard navigation, grouped options, remote data loading, and search filtering.

Basic

Grouped Options

Dynamic AJAX Data

PHP

PHP PHP Methods (Fluent)

Method / PropertyParametersDescription
$m->dropdown($id)stringCreate a dropdown component.
->dataSource($data)arraySet local data: [['value' => ..., 'text' => ...], ...].
->textField($field)stringProperty name to display (default: "text").
->valueField($field)stringProperty name for the value (default: "value").
->groupedDataSource($groups)arrayGrouped data: [['group' => 'Label', 'items' => [...]]].
->placeholder($text)stringPlaceholder text when nothing is selected.
->value($value)?stringSet the initially selected value.
->name($name)stringForm field name attribute.
->disabled()Disable the dropdown.
->remoteUrl($url)stringSet the AJAX endpoint for remote data loading.
->autoLoadRemote($auto)boolAuto-fetch remote data on initialisation (default: true).
->useLoader($use)boolShow a loading spinner while fetching (default: true).
->loaderText($text)stringCustom loading text.

JS JS Methods

Method / PropertyParametersDescription
m.dropdown(id, options)string, ?objectInitialise or get a dropdown instance.
value(val?)?stringGet or set the selected value.
text()Get the display text of the selected item.
dataSource(data?)?arrayGet or set the flat data source array. Clears any grouped data source.
groupedDataSource(data?)?arrayGet or set the grouped data source: [{group, items}, ...].
reload()Re-fetch data from the remote URL. Returns a Promise.
enable()Enable the dropdown.
disable()Disable and close the dropdown.
clear()Clear the current selection.
configure(options)objectUpdate configuration at runtime.

EVENT Events

Event NameDetailDescription
m:dropdown:change{value, text}Fired on the dropdown element when the selection changes. Listen with el.addEventListener('m:dropdown:change', fn). The underlying <select> also receives a native change event.