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 bedf5c1 commit 96af9cf
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 75 deletions.
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>
65 changes: 0 additions & 65 deletions app/code/Magento/Customer/view/frontend/web/js/trim-username.js

This file was deleted.

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;
});

0 comments on commit 96af9cf

Please sign in to comment.