Skip to content

Commit 4a1493a

Browse files
MAGETWO-51815: Invalid work of Password Strength Validator on "Create Customer" Storefront page
1 parent 36c5829 commit 4a1493a

File tree

4 files changed

+25
-36
lines changed

4 files changed

+25
-36
lines changed

app/code/Magento/Customer/view/frontend/templates/form/register.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@
147147
data-validate="{required:true, 'validate-customer-password':true}"
148148
autocomplete="off">
149149
<div id="password-strength-meter-container">
150-
<div id="password-strength-meter" class="password-strength-meter">
150+
<div id="password-strength-meter" data-role="password-strength-meter" class="password-strength-meter">
151151
<?php /* @escapeNotVerified */ echo __('Password Strength'); ?>:
152-
<span id="password-strength-meter-label">
152+
<span id="password-strength-meter-label" data-role="password-strength-meter-label" >
153153
<?php /* @escapeNotVerified */ echo __('No Password'); ?>
154154
</span>
155155
</div>

app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,30 @@
66
/**
77
* jshint browser:true
88
*/
9-
/*eslint no-unused-vars: 0*/
109
define([
1110
'jquery',
1211
'Magento_Customer/js/zxcvbn',
13-
'mage/translate',
14-
'mage/validation'
15-
], function ($, zxcvbn, $t, validation) {
12+
'mage/translate'
13+
], function ($, zxcvbn, $t) {
1614
'use strict';
1715

1816
$.widget('mage.passwordStrengthIndicator', {
1917
options: {
18+
cache: {},
2019
defaultClassName: 'password-strength-meter-',
21-
passwordStrengthMeterId: 'password-strength-meter-container',
22-
passwordStrengthMeterLabelId: 'password-strength-meter-label'
20+
passwordSelector: '[type=password]',
21+
passwordStrengthMeterSelector: '[data-role=password-strength-meter]',
22+
passwordStrengthMeterLabelSelector: '[data-role=password-strength-meter-label]'
2323
},
2424

2525
/**
2626
* Widget initialization
2727
* @private
2828
*/
2929
_create: function () {
30+
this.options.cache.input = $(this.options.passwordSelector, this.element);
31+
this.options.cache.meter = $(this.options.passwordStrengthMeterSelector, this.element);
32+
this.options.cache.label = $(this.options.passwordStrengthMeterLabelSelector, this.element);
3033
this._bind();
3134
},
3235

@@ -35,10 +38,10 @@ define([
3538
* @private
3639
*/
3740
_bind: function () {
38-
this._on({
39-
'change input[type="password"]': this._calculateStrength,
40-
'keyup input[type="password"]': this._calculateStrength,
41-
'paste input[type="password"]': this._calculateStrength
41+
this._on(this.options.cache.input, {
42+
'change': this._calculateStrength,
43+
'keyup': this._calculateStrength,
44+
'paste': this._calculateStrength
4245
});
4346
},
4447

@@ -54,7 +57,7 @@ define([
5457

5558
this._displayStrength(className, score, isEmpty);
5659
//update error messages
57-
$.validator.validateSingleElement(this.element.find('input[type="password"]'));
60+
$.validator.validateSingleElement(this.options.cache.input);
5861
},
5962

6063
/**
@@ -65,11 +68,7 @@ define([
6568
* @private
6669
*/
6770
_displayStrength: function (className, score, isEmpty) {
68-
var strengthContainer = this.element.find('#' + this.options.passwordStrengthMeterId),
69-
strengthLabel = '';
70-
71-
strengthContainer.removeClass();
72-
strengthContainer.addClass(className);
71+
var strengthLabel = '';
7372

7473
if (isEmpty) {
7574
strengthLabel = $t('No Password');
@@ -94,7 +93,10 @@ define([
9493
}
9594
}
9695

97-
this.element.find('#' + this.options.passwordStrengthMeterLabelId).text(strengthLabel);
96+
this.options.cache.meter
97+
.removeClass()
98+
.addClass(className);
99+
this.options.cache.label.text(strengthLabel);
98100
},
99101

100102
/**
@@ -103,7 +105,7 @@ define([
103105
* @private
104106
*/
105107
_getPassword: function () {
106-
return this.element.find('input[type="password"]').val();
108+
return this.options.cache.input.val();
107109
},
108110

109111
/**
@@ -114,8 +116,7 @@ define([
114116
* @private
115117
*/
116118
_getClassName: function (score, isEmpty) {
117-
var suffix = isEmpty ? 'no-pwd' : score;
118-
return this.options.defaultClassName + suffix;
119+
return this.options.defaultClassName + (isEmpty ? 'no-pwd' : score);
119120
}
120121
});
121122

app/design/frontend/Magento/blank/Magento_Customer/web/css/source/_module.less

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,7 @@
278278
}
279279
}
280280

281-
.password-strength-meter-0 & {
282-
&:before {
283-
background-color: @password-strength-color__weak;
284-
width: 25%;
285-
}
286-
}
287-
281+
.password-strength-meter-0,
288282
.password-strength-meter-1 & {
289283
&:before {
290284
background-color: @password-strength-color__weak;

app/design/frontend/Magento/luma/Magento_Customer/web/css/source/_module.less

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,7 @@
256256
}
257257
}
258258

259-
.password-strength-meter-0 & {
260-
&:before {
261-
background-color: @password-strength-color__weak;
262-
width: 25%;
263-
}
264-
}
265-
259+
.password-strength-meter-0,
266260
.password-strength-meter-1 & {
267261
&:before {
268262
background-color: @password-strength-color__weak;

0 commit comments

Comments
 (0)