Skip to content

Commit 0dd3eeb

Browse files
show or hide password widget created
1 parent e03d067 commit 0dd3eeb

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

app/code/Magento/Customer/view/frontend/requirejs-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var config = {
1212
passwordStrengthIndicator: 'Magento_Customer/js/password-strength-indicator',
1313
zxcvbn: 'Magento_Customer/js/zxcvbn',
1414
addressValidation: 'Magento_Customer/js/addressValidation',
15+
showPassword: 'Magento_Customer/js/show-password',
1516
'Magento_Customer/address': 'Magento_Customer/js/address',
1617
'Magento_Customer/change-email-password': 'Magento_Customer/js/change-email-password'
1718
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ use Magento\Customer\Block\Widget\Name;
104104
autocomplete="off" />
105105
</div>
106106
</div>
107+
<div class="field choice">
108+
<input type="checkbox" name="show-password" title="Show Password" id="show-password" class="checkbox" data-role="show-password" data-mage-init='{"showPassword": {"passwordSelector": "#current-password,#password,#password-confirmation"}}'>
109+
<label for="show-password" class="label"><span><?= $block->escapeHtml(__('Show Password')) ?></span></label>
110+
</div>
107111
</fieldset>
108112

109113
<fieldset class="fieldset additional_info">

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
data-validate="{required:true}">
4343
</div>
4444
</div>
45+
<div class="field choice">
46+
<input type="checkbox" name="show-password" title="Show Password" id="show-password" class="checkbox" data-role="show-password" data-mage-init='{"showPassword": {"passwordSelector": "#pass"}}'>
47+
<label for="show-password" class="label"><span><?= $block->escapeHtml(__('Show Password')) ?></span></label>
48+
</div>
4549
<?= $block->getChildHtml('form_additional_info') ?>
4650
<div class="actions-toolbar">
4751
<div class="primary"><button type="submit" class="action login primary" name="send" id="send2"><span><?= $block->escapeHtml(__('Sign In')) ?></span></button></div>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,10 @@ $formData = $block->getFormData();
259259
autocomplete="off">
260260
</div>
261261
</div>
262+
<div class="field choice">
263+
<input type="checkbox" name="show-password" title="Show Password" id="show-password" class="checkbox" data-role="show-password" data-mage-init='{"showPassword": {"passwordSelector": "#password,#password-confirmation"}}'>
264+
<label for="show-password" class="label"><span><?= $block->escapeHtml(__('Show Password')) ?></span></label>
265+
</div>
262266
</fieldset>
263267

264268
<fieldset class="fieldset additional_info">

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
<input type="password" class="input-text" name="password_confirmation" id="password-confirmation" data-validate="{required:true,equalTo:'#password'}" autocomplete="off">
3838
</div>
3939
</div>
40+
<div class="field choice">
41+
<input type="checkbox" name="show-password" title="Show Password" id="show-password" class="checkbox" data-role="show-password" data-mage-init='{"showPassword": {"passwordSelector": "#password,#password-confirmation"}}'>
42+
<label for="show-password" class="label"><span><?= $block->escapeHtml(__('Show Password')) ?></span></label>
43+
</div>
4044
</fieldset>
4145
<div class="actions-toolbar">
4246
<div class="primary">
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.showPassword', {
12+
options: {
13+
passwordSelector: '',
14+
showPasswordSelector: '[data-role=show-password]',
15+
passwordInputType: 'password',
16+
textInputType: 'text'
17+
},
18+
19+
/**
20+
* Widget initialization
21+
* @private
22+
*/
23+
_create: function () {
24+
this._bind();
25+
},
26+
27+
/**
28+
* Event binding, will monitor click event on show password.
29+
* @private
30+
*/
31+
_bind: function () {
32+
this._on(this.options.showPasswordSelector, {
33+
'click': this._showPassword
34+
});
35+
},
36+
37+
/**
38+
* Show/Hide password
39+
* @private
40+
*/
41+
_showPassword: function () {
42+
if ($(this.options.passwordSelector).attr("type") == this.options.passwordInputType) {
43+
$(this.options.passwordSelector).attr("type", this.options.textInputType);
44+
} else {
45+
$(this.options.passwordSelector).attr("type", this.options.passwordInputType);
46+
}
47+
}
48+
});
49+
});

0 commit comments

Comments
 (0)