From c24f6d3d51b53a42641ecf77e6e7664e2051e7cc Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 18 Mar 2013 15:28:12 -0400 Subject: [PATCH] Username change: check length in js, we don't need the server to do it --- .../preferences_username_controller.js | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/preferences_username_controller.js b/app/assets/javascripts/discourse/controllers/preferences_username_controller.js index 072d56b51..0ec57d910 100644 --- a/app/assets/javascripts/discourse/controllers/preferences_username_controller.js +++ b/app/assets/javascripts/discourse/controllers/preferences_username_controller.js @@ -26,18 +26,22 @@ Discourse.PreferencesUsernameController = Discourse.ObjectController.extend({ }).property('newUsername', 'content.username'), checkTaken: (function() { - var _this = this; - this.set('taken', false); - this.set('errorMessage', null); - if (this.blank('newUsername')) return; - if (this.get('unchanged')) return; - Discourse.User.checkUsername(this.get('newUsername')).then(function(result) { - if (result.errors) { - return _this.set('errorMessage', result.errors.join(' ')); - } else if (result.available === false) { - return _this.set('taken', true); - } - }); + if( this.get('newUsername') && this.get('newUsername').length < 3 ) { + this.set('errorMessage', Em.String.i18n('user.name.too_short')); + } else { + var _this = this; + this.set('taken', false); + this.set('errorMessage', null); + if (this.blank('newUsername')) return; + if (this.get('unchanged')) return; + Discourse.User.checkUsername(this.get('newUsername')).then(function(result) { + if (result.errors) { + return _this.set('errorMessage', result.errors.join(' ')); + } else if (result.available === false) { + return _this.set('taken', true); + } + }); + } }).observes('newUsername'), saveButtonText: (function() {