Created
March 25, 2015 18:18
-
-
Save turner/03095ec1a7ad9c7bd781 to your computer and use it in GitHub Desktop.
jQuery UI Dialog Widget. Extend options to support enter key triggering ok button press
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extend jquery ui dialog widget to support enter key triggering "ok" button press. | |
+ $.extend($.ui.dialog.prototype.options, { | |
+ | |
+ create: function() { | |
+ | |
+ var $this = $(this); | |
+ | |
+ // focus first button and bind enter to it | |
+ $this.parent().find('.ui-dialog-buttonpane button:first').focus(); | |
+ | |
+ $this.keypress(function(e) { | |
+ | |
+ if( e.keyCode == $.ui.keyCode.ENTER ) { | |
+ $this.parent().find('.ui-dialog-buttonpane button:first').click(); | |
+ return false; | |
+ } | |
+ | |
+ }); | |
+ } | |
+ | |
+ }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment