Dropdown
Custom select dropdown with keyboard navigation, grouped options, remote data loading, and search filtering.
Basic
Medium Priority
Select category...
Grouped Options
Select category...
Dynamic AJAX Data
Select...
Select an option to see output...
PHP PHP Methods (Fluent)
| Method / Property | Parameters | Description |
|---|---|---|
$m->dropdown($id) | string | Create a dropdown component. |
->dataSource($data) | array | Set local data: [['value' => ..., 'text' => ...], ...]. |
->textField($field) | string | Property name to display (default: "text"). |
->valueField($field) | string | Property name for the value (default: "value"). |
->groupedDataSource($groups) | array | Grouped data: [['group' => 'Label', 'items' => [...]]]. |
->placeholder($text) | string | Placeholder text when nothing is selected. |
->value($value) | ?string | Set the initially selected value. |
->name($name) | string | Form field name attribute. |
->disabled() | | Disable the dropdown. |
->remoteUrl($url) | string | Set the AJAX endpoint for remote data loading. |
->autoLoadRemote($auto) | bool | Auto-fetch remote data on initialisation (default: true). |
->useLoader($use) | bool | Show a loading spinner while fetching (default: true). |
->loaderText($text) | string | Custom loading text. |
JS JS Methods
| Method / Property | Parameters | Description |
|---|---|---|
m.dropdown(id, options) | string, ?object | Initialise or get a dropdown instance. |
value(val?) | ?string | Get or set the selected value. |
text() | | Get the display text of the selected item. |
dataSource(data?) | ?array | Get or set the flat data source array. Clears any grouped data source. |
groupedDataSource(data?) | ?array | Get 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) | object | Update configuration at runtime. |
EVENT Events
| Event Name | Detail | Description |
|---|---|---|
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. |