1

I have a form textfield element, which contains autocomplete feature using #autocomplete_route_name.

Could you clarify me, how to call ajax function when the textfield value has been set via autocomplete ? That is, for example, an user has selected a value from the autocomplete list, set it into the textbox and right away something should be executed via ajax depending on new value of the textbox.

Which ajax event should I use for it ?

1 Answer 1

0

I managed to find the solution. My code works with an event "autocompleteselect".

Here's an example of code

$form['autocomplete_field'] = [
            '#type' => 'textfield',
            '#title' => t('Autocomplete search'),
            '#autocomplete_route_name' => 'autocomplete_route',
            '#ajax' => [
                'callback' => '::ajaxFunctionAfterAutocomplete',
                'event' => 'autocompleteselect',
            ]
        ];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.