Skip to content

Instantly share code, notes, and snippets.

@turner
Created March 25, 2015 18:18
Show Gist options
  • Save turner/03095ec1a7ad9c7bd781 to your computer and use it in GitHub Desktop.
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
// 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