Autocomplete search inside a dropdown

Hello everyone,

I’m trying to display a search inside a backend relation widget. Exactly like the one available for dropdown form field types.

Is there a way to do this with the default widget or I need to create a custom one?

This is possible by building a custom form widget and using this markup to render the select:

<select
    class="form-control custom-select"
    style="width: 200px"
    data-handler="onGetSelectOptions"
    data-minimum-input-length="1"
    data-ajax--delay="300"
    data-request-data="foo: 'bar'">
</select>

Then this is an example AJAX handler for the results:

public function onGetSelectOptions()
{
    return [
        'results' => [
            'w25' => 'Width 25',
            'h40' => 'Height 40',
            'p90' => 'Padding 40',
        ]
    ];
}
1 Like