When ever I submit a form using ajax, the element that triggered the submit gets focus. I don't want this behavior if I'm using infinite scroll and I want to keep the user at the bottom of the page. How do I fix this?
Focus returns to this element:
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Search'),
'#attributes' => [
'class' => [
'btn',
'btn-md',
'btn-primary',
'use-ajax-submit'
]
],
'#ajax' => [
'wrapper' => $wrapper,
]
];
To solve this problem I added the following changes:
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Search'),
'#attributes' => [
'class' => [
'btn',
'btn-md',
'btn-primary',
'use-ajax-submit'
]
],
'#ajax' => [
'wrapper' => $wrapper,
'disable-refocus' => true
]
];
The disable-refocus flag prevents the automatic refocus.
See: Focus state bug on text field AJAX calls
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With