Skip to content

[Backport-2.1] Trim email address in customer account create and login form #16297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<div class="field email required">
<label class="label" for="email"><span><?php echo $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<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}">
<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}">
</div>
</div>
<div class="field password required">
Expand All @@ -51,12 +51,3 @@
</div>
</div>

<script type="text/x-magento-init">
{
".field.email": {
"Magento_Customer/js/trim-username": {
"formSelector": "form.form-login"
}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
<div class="field required">
<label for="email_address" class="label"><span><?php echo $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFormData()->getEmail()) ?>" title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Email')) ?>" class="input-text" data-validate="{required:true, 'validate-email':true}">
<input type="email" name="email" autocomplete="email" id="email_address" value="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr($block->getFormData()->getEmail()) ?>" title="<?php echo $this->helper(\Magento\Framework\EscapeHelper::class)->escapeHtmlAttr(__('Email')) ?>" class="input-text" data-mage-init='{"mage/trim-input":{}}' data-validate="{required:true, 'validate-email':true}">
</div>
</div>
<div class="field password required" data-mage-init='{"passwordStrengthIndicator": {}}'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ define(

/** Show login popup window */
showModal: function () {
$(this.modalWindow).modal('openModal');
$(this.modalWindow).modal('openModal').trigger('contentUpdated');
}
}
}
Expand Down
65 changes: 0 additions & 65 deletions app/code/Magento/Customer/view/frontend/web/js/trim-username.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
id="email"
type="email"
class="input-text"
data-mage-init='{"mage/trim-input":{}}'
data-bind="attr: {autocomplete: autocomplete}"
data-validate="{required:true, 'validate-email':true}">
</div>
Expand Down
60 changes: 60 additions & 0 deletions lib/web/mage/trim-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'jquery'
], function ($) {
'use strict';

$.widget('mage.trimInput', {
options: {
cache: {}
},

/**
* Widget initialization
* @private
*/
_create: function () {
this.options.cache.input = $(this.element);
this._bind();
},

/**
* Event binding, will monitor change, keyup and paste events.
* @private
*/
_bind: function () {
if (this.options.cache.input.length) {
this._on(this.options.cache.input, {
'change': this._trimInput,
'keyup': this._trimInput,
'paste': this._trimInput
});
}
},

/**
* Trim value
* @private
*/
_trimInput: function () {
var input = this._getInputValue().trim();

this.options.cache.input.val(input);
},

/**
* Get input value
* @returns {*}
* @private
*/
_getInputValue: function () {
return this.options.cache.input.val();
}
});

return $.mage.trimInput;
});