Autofocus input in twitter bootstrap modal
try removing tabindex="-1" and it works fine.
<div class="modal fade" id="modalID" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal fade" id="modalID" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
Hope this helps!
I'm using Bootstrap 3.0 (hopefully, this works with 3.1 as well).
We had to use tabindex="-1"
because that allows the ESC key to close the modal.
So I was able to fix this issue using:
// Every time a modal is shown, if it has an autofocus element, focus on it.
$('.modal').on('shown.bs.modal', function() {
$(this).find('[autofocus]').focus();
});