Skip to content

Commit 60521be

Browse files
author
Stanislav Idolov
authored
ENGCOM-2082: [Forwardport 2.3] Trim email address in customer account create and login form #16293
2 parents d927f46 + fb735e0 commit 60521be

File tree

6 files changed

+64
-77
lines changed

6 files changed

+64
-77
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/templates/form/register.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
<div class="field required">
132132
<label for="email_address" class="label"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
133133
<div class="control">
134-
<input type="email" name="email" autocomplete="email" id="email_address" value="<?= $block->escapeHtmlAttr($block->getFormData()->getEmail()) ?>" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
134+
<input type="email" name="email" autocomplete="email" id="email_address" value="<?= $block->escapeHtmlAttr($block->getFormData()->getEmail()) ?>" title="<?= $block->escapeHtmlAttr(__('Email')) ?>" class="input-text" data-mage-init='{"mage/trim-input":{}}' data-validate="{required:true, 'validate-email':true}">
135135
</div>
136136
</div>
137137
<div class="field password required">

app/code/Magento/Customer/view/frontend/web/js/model/authentication-popup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ define([
3434

3535
/** Show login popup window */
3636
showModal: function () {
37-
$(this.modalWindow).modal('openModal');
37+
$(this.modalWindow).modal('openModal').trigger('contentUpdated');
3838
}
3939
};
4040
});

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

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

app/code/Magento/Customer/view/frontend/web/template/authentication-popup.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
id="customer-email"
6161
type="email"
6262
class="input-text"
63+
data-mage-init='{"mage/trim-input":{}}'
6364
data-bind="attr: {autocomplete: autocomplete}"
6465
data-validate="{required:true, 'validate-email':true}">
6566
</div>

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)