Search code examples
formstwitter-bootstrapmodal-dialog

Avoid modal dismiss on enter keypress


I have set up a bootstrap modal with a form inside it, I just noticed that when I press the Enter key, the modal gets dismissed. Is there a way not to dismiss it when pressing Enter?

I tried activating the modal with keyboard:false, but that only prevents dismissal with the ESC key.


Solution

  • I just had this problem too.
    My problem was that i had a close button in my modal

    <button class="close" data-dismiss="modal">&times;</button>
    

    Pressing enter in the input field caused this button to be fired. I changed it to an anchor instead and it works as expected now (enter submits the form and does not close the modal).

    <a class="close" data-dismiss="modal">&times;</a>
    

    Without seeing your source, I can't confirm that your cause is the same though.