A
A
AleksMedovnik2018-08-11 09:58:36
JavaScript
AleksMedovnik, 2018-08-11 09:58:36

How to focus on a modal form using Bootstrap?

Hello!
There is a modal window with a form using Bootstrap. It is necessary to focus on the form every time the modal window is opened without reloading the page.
Added "autofocus" attribute to "input". But focusing happens only after page reload.
And, JS - settings:
$('#myModal_1').modal({
focus: true
});
opens a modal window immediately upon initialization.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gerasimov, 2018-08-11
@Medovnik

The very first example in the modal documentation is just for you https://getbootstrap.com/docs/4.0/components/modal/

$('#myModal').on('shown.bs.modal', function () {
  $('#myInput').trigger('focus')
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question