From 9ecb84b8c17413eac3b125f3893644c161cc4e14 Mon Sep 17 00:00:00 2001 From: Piyush Dankhara Date: Sat, 19 May 2018 03:04:42 -0700 Subject: [PATCH 1/3] Trim username on customer account login page --- .../view/frontend/requirejs-config.js | 1 + .../view/frontend/templates/form/login.phtml | 10 +++ .../view/frontend/web/js/trim-username.js | 65 +++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 app/code/Magento/Customer/view/frontend/web/js/trim-username.js diff --git a/app/code/Magento/Customer/view/frontend/requirejs-config.js b/app/code/Magento/Customer/view/frontend/requirejs-config.js index 20dd53ded11c9..8290df9272ec6 100644 --- a/app/code/Magento/Customer/view/frontend/requirejs-config.js +++ b/app/code/Magento/Customer/view/frontend/requirejs-config.js @@ -9,6 +9,7 @@ var config = { checkoutBalance: 'Magento_Customer/js/checkout-balance', address: 'Magento_Customer/address', changeEmailPassword: 'Magento_Customer/change-email-password', + trimUsername: 'Magento_Customer/js/trim-username', passwordStrengthIndicator: 'Magento_Customer/js/password-strength-indicator', zxcvbn: 'Magento_Customer/js/zxcvbn', addressValidation: 'Magento_Customer/js/addressValidation' diff --git a/app/code/Magento/Customer/view/frontend/templates/form/login.phtml b/app/code/Magento/Customer/view/frontend/templates/form/login.phtml index 16206525aa53b..ebc6a66bc6a73 100644 --- a/app/code/Magento/Customer/view/frontend/templates/form/login.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/form/login.phtml @@ -42,3 +42,13 @@ + + diff --git a/app/code/Magento/Customer/view/frontend/web/js/trim-username.js b/app/code/Magento/Customer/view/frontend/web/js/trim-username.js new file mode 100644 index 0000000000000..4c5c8c9dd8ff2 --- /dev/null +++ b/app/code/Magento/Customer/view/frontend/web/js/trim-username.js @@ -0,0 +1,65 @@ +/** + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'jquery', +], function ($) { + 'use strict'; + + $.widget('mage.trimUsername', { + options: { + cache: {}, + formSelector: 'form', + emailSelector: 'input[type="email"]' + }, + + /** + * Widget initialization + * @private + */ + _create: function () { + // We need to look outside the module for backward compatibility, since someone can already use the module. + // @todo Narrow this selector in 2.3 so it doesn't accidentally finds the the email field from the + // newsletter email field or any other "email" field. + this.options.cache.email = $(this.options.formSelector).find(this.options.emailSelector); + this._bind(); + }, + + /** + * Event binding, will monitor change, keyup and paste events. + * @private + */ + _bind: function () { + if (this.options.cache.email.length) { + this._on(this.options.cache.email, { + 'change': this._trimUsername, + 'keyup': this._trimUsername, + 'paste': this._trimUsername + }); + } + }, + + /** + * Trim username + * @private + */ + _trimUsername: function () { + var username = this._getUsername().trim(); + + this.options.cache.email.val(username); + }, + + /** + * Get username value + * @returns {*} + * @private + */ + _getUsername: function () { + return this.options.cache.email.val(); + } + }); + + return $.mage.trimUsername; +}); From 62c1a146dab6f7d6c0e553de581e9886f9fedf44 Mon Sep 17 00:00:00 2001 From: Vishal Gelani Date: Sun, 20 May 2018 06:28:56 +0530 Subject: [PATCH 2/3] Removed extra comma of element --- app/code/Magento/Customer/view/frontend/web/js/trim-username.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Customer/view/frontend/web/js/trim-username.js b/app/code/Magento/Customer/view/frontend/web/js/trim-username.js index 4c5c8c9dd8ff2..69f89cb8fe01f 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/trim-username.js +++ b/app/code/Magento/Customer/view/frontend/web/js/trim-username.js @@ -4,7 +4,7 @@ */ define([ - 'jquery', + 'jquery' ], function ($) { 'use strict'; From c81d9a69d890990cb81a160036762c2dc1b44369 Mon Sep 17 00:00:00 2001 From: Piyush Dankhara Date: Tue, 29 May 2018 10:41:37 -0700 Subject: [PATCH 3/3] Remove trimUsername declaration from requirejs-config.js and use path inside template --- app/code/Magento/Customer/view/frontend/requirejs-config.js | 1 - .../Magento/Customer/view/frontend/templates/form/login.phtml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/view/frontend/requirejs-config.js b/app/code/Magento/Customer/view/frontend/requirejs-config.js index 8290df9272ec6..20dd53ded11c9 100644 --- a/app/code/Magento/Customer/view/frontend/requirejs-config.js +++ b/app/code/Magento/Customer/view/frontend/requirejs-config.js @@ -9,7 +9,6 @@ var config = { checkoutBalance: 'Magento_Customer/js/checkout-balance', address: 'Magento_Customer/address', changeEmailPassword: 'Magento_Customer/change-email-password', - trimUsername: 'Magento_Customer/js/trim-username', passwordStrengthIndicator: 'Magento_Customer/js/password-strength-indicator', zxcvbn: 'Magento_Customer/js/zxcvbn', addressValidation: 'Magento_Customer/js/addressValidation' diff --git a/app/code/Magento/Customer/view/frontend/templates/form/login.phtml b/app/code/Magento/Customer/view/frontend/templates/form/login.phtml index ebc6a66bc6a73..77e250c5de923 100644 --- a/app/code/Magento/Customer/view/frontend/templates/form/login.phtml +++ b/app/code/Magento/Customer/view/frontend/templates/form/login.phtml @@ -46,7 +46,7 @@