Skip to content

Commit 96af9cf

Browse files
committed
Improve trim email address in customer account login page
1 parent bedf5c1 commit 96af9cf

File tree

3 files changed

+61
-75
lines changed

3 files changed

+61
-75
lines changed

app/code/Magento/Customer/view/frontend/templates/form/login.phtml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<div class="field email required">
3333
<label class="label" for="email"><span><?php echo $block->escapeHtml(__('Email')) ?></span></label>
3434
<div class="control">
35-
<input name="login[username]" value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getUsername()) ?>" <?php if ($block->isAutocompleteDisabled()) :?> autocomplete="off"<?php endif; ?> id="email" type="email" class="input-text" title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Email')) ?>" data-validate="{required:true, 'validate-email':true}">
35+
<input name="login[username]" value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getUsername()) ?>" <?php if ($block->isAutocompleteDisabled()) :?> autocomplete="off"<?php endif; ?> id="email" type="email" class="input-text" title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Email')) ?>" data-mage-init='{"mage/trim-input":{}}' data-validate="{required:true, 'validate-email':true}">
3636
</div>
3737
</div>
3838
<div class="field password required">
@@ -51,12 +51,3 @@
5151
</div>
5252
</div>
5353

54-
<script type="text/x-magento-init">
55-
{
56-
".field.email": {
57-
"Magento_Customer/js/trim-username": {
58-
"formSelector": "form.form-login"
59-
}
60-
}
61-
}
62-
</script>

app/code/Magento/Customer/view/frontend/web/js/trim-username.js

Lines changed: 0 additions & 65 deletions
This file was deleted.

lib/web/mage/trim-input.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery'
8+
], function ($) {
9+
'use strict';
10+
11+
$.widget('mage.trimInput', {
12+
options: {
13+
cache: {}
14+
},
15+
16+
/**
17+
* Widget initialization
18+
* @private
19+
*/
20+
_create: function () {
21+
this.options.cache.input = $(this.element);
22+
this._bind();
23+
},
24+
25+
/**
26+
* Event binding, will monitor change, keyup and paste events.
27+
* @private
28+
*/
29+
_bind: function () {
30+
if (this.options.cache.input.length) {
31+
this._on(this.options.cache.input, {
32+
'change': this._trimInput,
33+
'keyup': this._trimInput,
34+
'paste': this._trimInput
35+
});
36+
}
37+
},
38+
39+
/**
40+
* Trim value
41+
* @private
42+
*/
43+
_trimInput: function () {
44+
var input = this._getInputValue().trim();
45+
46+
this.options.cache.input.val(input);
47+
},
48+
49+
/**
50+
* Get input value
51+
* @returns {*}
52+
* @private
53+
*/
54+
_getInputValue: function () {
55+
return this.options.cache.input.val();
56+
}
57+
});
58+
59+
return $.mage.trimInput;
60+
});

0 commit comments

Comments
 (0)