Twitter bootstrap modal input field focus

后端 未结 9 761
不知归路
不知归路 2020-12-08 03:56

I have the following modal form from example:




        
9条回答
  •  感动是毒
    2020-12-08 04:40

    I think the updated answer is pretty clever. Here is another way to solve it.

    Bootstrap 3.2's js file includes a script to manage focus during and after the modal's fade transition. This interferes with any jQuery, javascript or rails+HTML5 focusing on a form field in the modal - bootstrap removes your focus after the modal loads.

    To remove bootstrap's ability to override your focus, comment out this line in the Modal script area:

    transition ?
        that.$element.find('.modal-dialog') // wait for modal to slide in
          .one($.support.transition.end, function () {
            // that.$element.focus().trigger(e)
            // the line above is stealing your focus after modal loads!
          })
          .emulateTransitionEnd(300) :
        that.$element.focus().trigger(e) 
    

    Now your field should be able to have focus in any modal form.

提交回复
热议问题