Search code examples
javascriptjqueryhtmltwitter-bootstraptwitter-bootstrap-2

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


Solution

  • 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();
    });