Utsav Naik
Utsav Naik

Reputation: 15

bootsprap 2.1 modal autofocus not working

ISSUE : Auto focus is not applying to my pop up form of bootstrap 2.1

I am using twitter bootstrap 2.1 trying to autofocus on first input element when click and a pop up is show.

I need guidance to resolve this issue. I have try with JavaScript focus function and also try with html autofocus property but it is not applying.

Bootstrap modal show event

I tried this stack overflow question but it require to update my bootstrap to 3.0 but it is not possible for me to update as it require huge time.

I want similar autofocus with bootstrap 2.1 please guide me towards this.

Thanks in advance

Upvotes: 0

Views: 427

Answers (2)

Utsav Naik
Utsav Naik

Reputation: 15

its general solutions for all used modal no need to write method for individual modal you can try this

$('.modal').on('shown', function () {
        var first_elemt = $('.modal').filter(':visible:first').find('input[type=text]').attr('id');
       $('#'+first_elemt).focus();
     });

Upvotes: 1

Ravi Patel
Ravi Patel

Reputation: 763

I solve this...

Bootstarp model have "shown" event. It fires after model open. Just put your code for focus first element of form on the event function. Like below

$('your-model-id').on('shown', function () {
  $('#your-text-box-id').focus();
});

Upvotes: 1

Related Questions