Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default button in bootstrap modal dialog

I am trying to set the default button in a bootstrap modal. Here is the code: http://plnkr.co/edit/1aLlDdL8WfkUrBVt4q31?p=preview

In the modal window, I want the Submit button to be the default.

enter image description here

I tried to follow code but did not work.

$("#userNameModal").keyup(function(event){
       if(event.keyCode == 13){
           $("#submitUserNameBtn").click();
       }
});

Any help is appreciated.

like image 627
JGV Avatar asked May 27 '15 23:05

JGV


People also ask

How do I add a button to modal popup?

To trigger the modal window, you need to use a button or a link. Then include the two data-* attributes: data-toggle="modal" opens the modal window. data-target="#myModal" points to the id of the modal.

How do I show default modal?

Answer: Use the Bootstrap . modal('show') method modal('show') method for launching the modal window automatically when page load without clicking anything. A common example of this technique is loading the modal when user landed on the home page and requesting them to subscribe the website newsletter.

How do I keep my Bootstrap modal from closing when I click the button?

$('#buttonId'). off('click'). click(function(clickEvent){ //enter code here }); you actually can prevent the closing of your modal.

What is backdrop in modal?

The backdrop option specifies whether the modal should have a dark overlay (the background color of the current page) or not.


1 Answers

Wrap the code with <form> and set correct button types: type="submit" for Submit button and type="button" for other ones.

The modified plunker: http://plnkr.co/edit/XD2UzlBnPbBafWmWfTg0?p=preview

like image 190
user3707125 Avatar answered Oct 05 '22 19:10

user3707125