forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Forwardport 2.3] Trim username on customer account login page
- Loading branch information
1 parent
6110fdd
commit c44f1f8
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/code/Magento/Customer/view/frontend/web/js/trim-username.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 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; | ||
}); |