Merge pull request #954 from jgable/fixChangePasswordEnter

Fix pressing enter key on user settings
This commit is contained in:
Hannah Wolfe 2013-10-05 12:25:26 -07:00
commit cd929f19b3
2 changed files with 31 additions and 5 deletions

View File

@ -19,7 +19,7 @@
<figure class="user-image"> <figure class="user-image">
<a id="user-image" class="img" {{#if image}}style="background-image: url({{image}});"{{/if}} href="#"><span class="hidden">{{name}}'s Picture</span></a> <a id="user-image" class="img" {{#if image}}style="background-image: url({{image}});"{{/if}} href="#"><span class="hidden">{{name}}'s Picture</span></a>
<button class="edit-user-image js-modal-image">Edit Picture</button> <button type="button" class="edit-user-image js-modal-image">Edit Picture</button>
</figure> </figure>
<div class="form-group"> <div class="form-group">
@ -78,7 +78,7 @@
<input type="password" id="user-new-password-verification" /> <input type="password" id="user-new-password-verification" />
</div> </div>
<div class="form-group"> <div class="form-group">
<button class="button-delete button-change-password">Change Password</button> <button type="button" class="button-delete button-change-password">Change Password</button>
</div> </div>
</fieldset> </fieldset>

View File

@ -234,6 +234,8 @@
// ### User profile // ### User profile
Settings.user = Settings.Pane.extend({ Settings.user = Settings.Pane.extend({
templateName: 'settings/user-profile',
id: 'user', id: 'user',
options: { options: {
@ -244,7 +246,8 @@
'click .button-save': 'saveUser', 'click .button-save': 'saveUser',
'click .button-change-password': 'changePassword', 'click .button-change-password': 'changePassword',
'click .js-modal-cover': 'showCover', 'click .js-modal-cover': 'showCover',
'click .js-modal-image': 'showImage' 'click .js-modal-image': 'showImage',
'keyup .user-profile': 'handleEnterKeyOnForm'
}, },
showCover: function (e) { showCover: function (e) {
e.preventDefault(); 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 () { saveUser: function () {
var userName = this.$('#user-name').val(), var userName = this.$('#user-name').val(),
@ -369,8 +397,6 @@
} }
}, },
templateName: 'settings/user-profile',
afterRender: function () { afterRender: function () {
var self = this; var self = this;
Countable.live(document.getElementById('user-bio'), function (counter) { Countable.live(document.getElementById('user-bio'), function (counter) {