Skip to content

Commit

Permalink
FormValidator: Add option to show/hide password - refs BT#18449
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Apr 30, 2021
1 parent 4cd8dd8 commit d843439
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 22 deletions.
24 changes: 2 additions & 22 deletions main/admin/user_add.php
Expand Up @@ -16,7 +16,7 @@
$is_platform_admin = api_is_platform_admin() ? 1 : 0;

$message = null;
$htmlHeadXtra[] = api_get_password_checker_js('#username', '#password');
$htmlHeadXtra[] = api_get_password_checker_js('#username', '#add-user__input-password');
$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css');
$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js');
$htmlHeadXtra[] = '
Expand Down Expand Up @@ -55,16 +55,6 @@ function updateStatus(){
document.getElementById("id_platform_admin").style.display="none";
}
}
function ShowHidePassword() {
if ($(\'#showPassword\').prop(\'checked\')) {
$(\'#password\').attr(\'type\',\'text\');
$(\'.showPasswordEye\').removeClass(\'fa-eye\').addClass(\'fa-eye-slash\');
} else {
$(\'#password\').attr(\'type\',\'password\');
$(\'.showPasswordEye\').addClass(\'fa-eye\').removeClass(\'fa-eye-slash\');
}
}
</script>';

if (!empty($_GET['message'])) {
Expand Down Expand Up @@ -219,22 +209,12 @@ function ShowHidePassword() {
'id' => 'password',
'autocomplete' => 'new-password',
'onkeydown' => 'javascript: password_switch_radio_button();',
'show_hide' => true,
//'required' => 'required'
]
);

$form->addGroup($group, 'password', get_lang('Password'));
$form->addElement(
'checkbox',
'showPassword',
get_lang('ShowOrHide')." ".get_lang('Password')." ".
Display::returnFontAwesomeIcon('eye', null, true, 'showPasswordEye'),
'',
[
'id' => 'showPassword',
'onchange' => 'javascript: ShowHidePassword();',
]
);
$form->addPasswordRule('password', 'password');
$form->addGroupRule('password', get_lang('EnterPassword'), 'required', null, 1);

Expand Down
32 changes: 32 additions & 0 deletions main/inc/lib/pear/HTML/QuickForm/password.php
Expand Up @@ -95,4 +95,36 @@ public function getFrozenHtml()
return ('' != $value ? '**********' : '&nbsp;').
$this->_getPersistantData();
}

/**
* @return string
*/
public function toHtml()
{
if (parent::isFrozen()) {
return parent::getFrozenHtml();
}

$input = '<input '.$this->_getAttrString($this->_attributes).' />';

if (empty($this->_attributes['show_hide'])) {
return $input;
}

$this->removeAttribute('show_hide');

$label = get_lang('ShowOrHide');
$pwdId = $this->_attributes['id'];
$id = $pwdId.'_toggle';

return '<div class="input-group" id="add-user__input-password">
'.$input.'
<span class="input-group-addon">
<input type="checkbox" title="'.$label.'" aria-label="'.$label.'" id="'.$id.'">
</span>
</div>
<script>document.getElementById(\''.$id.'\').onchange = function () {
document.getElementById(\''.$pwdId.'\').setAttribute(\'type\', this.checked ? \'text\' : \'password\')
};</script>';
}
}

0 comments on commit d843439

Please sign in to comment.