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.
I tried to follow code but did not work.
$("#userNameModal").keyup(function(event){
if(event.keyCode == 13){
$("#submitUserNameBtn").click();
}
});
Any help is appreciated.
Since you are using Angular i would just use a directive. That way you can use it across your app (also at the bottom is the link for the working plnkr):
.directive('enterSubmit', function() {
return {
restrict: 'A',
link: function(scope, elem, attrs) {
elem.bind('keydown', function(event) {
var code = event.keyCode || event.which;
if (code === 13) {
if (!event.shiftKey) {
event.preventDefault();
scope.$apply(attrs.enterSubmit);
}
}
});
}
}
});
Then call it from you input:
enter-submit="submitUserName()"
HERE IS THE WORKING REVISED PLNKR: http://plnkr.co/edit/STXwWPxWIWpDSkIo9ruG?p=preview
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments