Skip to content

Commit 89ca28f

Browse files
committed
Improve trim email address in customer account login page
1 parent 8eb668b commit 89ca28f

File tree

3 files changed

+62
-75
lines changed

3 files changed

+62
-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
@@ -24,7 +24,7 @@
2424
<div class="field email required">
2525
<label class="label" for="email"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
2626
<div class="control">
27-
<input name="login[username]" value="<?= $block->escapeHtmlAttr($block->getUsername()) ?>" <?php if ($block->isAutocompleteDisabled()): ?> autocomplete="off"<?php endif; ?> id="email" type="email" class="input-text" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" data-validate="{required:true, 'validate-email':true}">
27+
<input name="login[username]" value="<?= $block->escapeHtmlAttr($block->getUsername()) ?>" <?php if ($block->isAutocompleteDisabled()): ?> autocomplete="off"<?php endif; ?> id="email" type="email" class="input-text" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" data-mage-init='{"mage/trim-input":{}}' data-validate="{required:true, 'validate-email':true}">
2828
</div>
2929
</div>
3030
<div class="field password required">
@@ -43,12 +43,3 @@
4343
</div>
4444
</div>
4545

46-
<script type="text/x-magento-init">
47-
{
48-
".field.email": {
49-
"Magento_Customer/js/trim-username": {
50-
"formSelector": "form.form-login"
51-
}
52-
}
53-
}
54-
</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: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
});
61+

0 commit comments

Comments
 (0)