From 986d5c6299ca4449eaca8d77bcd666e87ec4364b Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Tue, 1 Oct 2013 10:05:12 -0500 Subject: [PATCH] Fix pressing enter key on user settings Specified type='button' for the buttons in the form so they don't get pseudo clicked on enter key in inputs. Added a keyup handler to check for enter keys in the inputs and do the proper action based on where you are in the form. --- core/client/tpl/settings/user-profile.hbs | 4 +-- core/client/views/settings.js | 32 ++++++++++++++++++++--- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/core/client/tpl/settings/user-profile.hbs b/core/client/tpl/settings/user-profile.hbs index 12255a8f27..23d4bb78f5 100644 --- a/core/client/tpl/settings/user-profile.hbs +++ b/core/client/tpl/settings/user-profile.hbs @@ -19,7 +19,7 @@
- +
@@ -78,7 +78,7 @@
- +
diff --git a/core/client/views/settings.js b/core/client/views/settings.js index 3cbbd9fbfc..4c38afbf86 100644 --- a/core/client/views/settings.js +++ b/core/client/views/settings.js @@ -234,6 +234,8 @@ // ### User profile Settings.user = Settings.Pane.extend({ + templateName: 'settings/user-profile', + id: 'user', options: { @@ -244,7 +246,8 @@ 'click .button-save': 'saveUser', 'click .button-change-password': 'changePassword', 'click .js-modal-cover': 'showCover', - 'click .js-modal-image': 'showImage' + 'click .js-modal-image': 'showImage', + 'keyup .user-profile': 'handleEnterKeyOnForm' }, showCover: function (e) { e.preventDefault(); @@ -281,6 +284,31 @@ })); }, + handleEnterKeyOnForm: function (ev) { + // Don't worry about it unless it's an enter key + if (ev.which !== 13) { + return; + } + + var $target = $(ev.target); + + if ($target.is("textarea")) { + // Allow enter key on user bio text area. + return; + } + + if ($target.is('input[type=password]')) { + // Change password if on a password input + return this.changePassword(ev); + } + + // Simulate clicking save otherwise + ev.preventDefault(); + + this.saveUser(ev); + + return false; + }, saveUser: function () { var userName = this.$('#user-name').val(), @@ -369,8 +397,6 @@ } }, - templateName: 'settings/user-profile', - afterRender: function () { var self = this; Countable.live(document.getElementById('user-bio'), function (counter) {