Skip to content

Commit

Permalink
Improve trim email address in customer account login page
Browse files Browse the repository at this point in the history
  • Loading branch information
dankhrapiyush committed Jun 21, 2018
1 parent 8eb668b commit 89ca28f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<div class="field email required">
<label class="label" for="email"><span><?= $block->escapeHtml(__('Email')) ?></span></label>
<div class="control">
<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}">
<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}">
</div>
</div>
<div class="field password required">
Expand All @@ -43,12 +43,3 @@
</div>
</div>

<script type="text/x-magento-init">
{
".field.email": {
"Magento_Customer/js/trim-username": {
"formSelector": "form.form-login"
}
}
}
</script>
65 changes: 0 additions & 65 deletions app/code/Magento/Customer/view/frontend/web/js/trim-username.js

This file was deleted.

61 changes: 61 additions & 0 deletions lib/web/mage/trim-input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* 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;
});

0 comments on commit 89ca28f

Please sign in to comment.