Skip to content

Commit c816799

Browse files
Magento bindings used and refactored show password uicomponent
1 parent 7c0e401 commit c816799

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

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

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,30 @@
55

66
define([
77
'jquery',
8-
'ko',
98
'uiComponent'
10-
], function ($, ko, Component) {
9+
], function ($, Component) {
1110
'use strict';
1211

1312
return Component.extend({
1413
passwordSelector: '',
15-
showPasswordSelector: '[data-role=show-password]',
1614
passwordInputType: 'password',
1715
textInputType: 'text',
1816

1917
defaults: {
20-
template: 'Magento_Customer/show-password'
21-
},
22-
23-
/** @inheritdoc */
24-
initialize: function () {
25-
this._super();
18+
template: 'Magento_Customer/show-password',
19+
isPasswordVisible: false
2620
},
2721

2822
/**
2923
* @return {Object}
3024
*/
3125
initObservable: function () {
32-
var self = this;
33-
3426
this._super()
35-
.observe({
36-
isChecked: ko.observable(false)
37-
});
27+
.observe(['isPasswordVisible']);
3828

39-
this.isChecked.subscribe(function () {
40-
self._showPassword();
41-
});
29+
this.isPasswordVisible.subscribe(function (isChecked) {
30+
this._showPassword(isChecked);
31+
}.bind(this));
4232

4333
return this;
4434
},
@@ -47,12 +37,9 @@ define([
4737
* Show/Hide password
4838
* @private
4939
*/
50-
_showPassword: function () {
51-
var passwordField = this.passwordSelector;
52-
53-
$(passwordField).attr('type',
54-
$(passwordField).attr('type') === this.passwordInputType ?
55-
this.textInputType : this.passwordInputType
40+
_showPassword: function (isChecked) {
41+
$(this.passwordSelector).attr('type',
42+
isChecked ? this.textInputType : this.passwordInputType
5643
);
5744
}
5845
});

app/code/Magento/Customer/view/frontend/web/template/show-password.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
*/
66
-->
77

8-
<input type="checkbox" name="show-password" title="Show Password" id="show-password" class="checkbox" data-role="show-password" data-bind="checked: isChecked">
9-
<label for="show-password" class="label"><span data-bind="i18n: 'Show Password'"></span></label>
8+
<input type="checkbox" name="show-password" title="Show Password" id="show-password" class="checkbox" data-role="show-password" ko-checked="isPasswordVisible">
9+
<label for="show-password" class="label"><span translate="'Show Password'"></span></label>

0 commit comments

Comments
 (0)