- Issue created by @pbonnefoi
I have a custom form with the below elements. I want to trigger an ajax when a value has been selected. The problem with "change" is that I loose the focus on the element and therefore, there is a bug. If I keep typing, the selected value is split ans disappear from the autocomplete field.
$form['export_wrapper']['my_select'] = [
'#type' => 'entity_autocomplete_tagify',
'#target_type' => 'node',
'#tags' => TRUE,
'#selection_handler' => 'default',
'#selection_settings' => [
'target_bundles' => ['article'],
],
'#match_operator' => 'CONTAINS',
'#show_entity_id' => 1,
'#ajax' => [
'callback' => '::ajaxUpdateLinkField',
'event' => 'change',
'wrapper' => 'link-field-wrapper',
'progress' => [
'type' => 'throbber',
'message' => $this->t('Updating link...'),
],
],
];
$form['export_wrapper']['export_button'] = [
'#type' => 'link',
'#title' => $this->t('Export CSV'),
'#url' => $url,
'#attributes' => [
'class' => ['button', 'button--primary'],
'role' => 'button',
'id' => 'link-field-wrapper',
],
];
Create a custom form, start typing in the autocomplete field, select a value, (wait for the ajax to be triggered), keep typing and there is the bug.
Best solution would be to have a custom ajax event triggered when selecting value and keep the focus on the autocomplete field to keep typing and select another autocomplete item.
Active
1.2
Code