File tree Expand file tree Collapse file tree 2 files changed +75
-0
lines changed
app/code/Magento/Customer/view/frontend Expand file tree Collapse file tree 2 files changed +75
-0
lines changed Original file line number Diff line number Diff line change 4242 </form>
4343 </div>
4444</div>
45+
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>
Original file line number Diff line number Diff line change 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.trimUsername' , {
12+ options : {
13+ cache : { } ,
14+ formSelector : 'form' ,
15+ emailSelector : 'input[type="email"]'
16+ } ,
17+
18+ /**
19+ * Widget initialization
20+ * @private
21+ */
22+ _create : function ( ) {
23+ // We need to look outside the module for backward compatibility, since someone can already use the module.
24+ // @todo Narrow this selector in 2.3 so it doesn't accidentally finds the email field from the
25+ // newsletter email field or any other "email" field.
26+ this . options . cache . email = $ ( this . options . formSelector ) . find ( this . options . emailSelector ) ;
27+ this . _bind ( ) ;
28+ } ,
29+
30+ /**
31+ * Event binding, will monitor change, keyup and paste events.
32+ * @private
33+ */
34+ _bind : function ( ) {
35+ if ( this . options . cache . email . length ) {
36+ this . _on ( this . options . cache . email , {
37+ 'change' : this . _trimUsername ,
38+ 'keyup' : this . _trimUsername ,
39+ 'paste' : this . _trimUsername
40+ } ) ;
41+ }
42+ } ,
43+
44+ /**
45+ * Trim username
46+ * @private
47+ */
48+ _trimUsername : function ( ) {
49+ var username = this . _getUsername ( ) . trim ( ) ;
50+
51+ this . options . cache . email . val ( username ) ;
52+ } ,
53+
54+ /**
55+ * Get username value
56+ * @returns {* }
57+ * @private
58+ */
59+ _getUsername : function ( ) {
60+ return this . options . cache . email . val ( ) ;
61+ }
62+ } ) ;
63+
64+ return $ . mage . trimUsername ;
65+ } ) ;
You can’t perform that action at this time.
0 commit comments