Display: add option to show/hide password in legacy FormValidator control

pull/6053/head
Angel Fernando Quiroz Campos 9 months ago
parent 9225759e2e
commit e3c621d545
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 33
      public/main/inc/lib/pear/HTML/QuickForm/password.php
  2. 2
      public/main/inc/lib/pear/HTML/QuickForm/text.php

@ -21,6 +21,8 @@
* @link http://pear.php.net/package/HTML_QuickForm
*/
use Chamilo\CoreBundle\Component\Utils\ActionIcon;
/**
* HTML class for a password type field
*
@ -47,7 +49,7 @@ class HTML_QuickForm_password extends HTML_QuickForm_text
*/
public function __construct($elementName = null, $elementLabel = null, $attributes = null)
{
$attributes['class'] = isset($attributes['class']) ? $attributes['class'] : 'form-control';
$attributes['class'] = $attributes['class'] ?? '';
parent::__construct($elementName, $elementLabel, $attributes);
$this->setType('password');
}
@ -95,4 +97,33 @@ class HTML_QuickForm_password extends HTML_QuickForm_text
return ('' != $value ? '**********' : ' ').
$this->_getPersistantData();
}
public function toHtml(): string
{
if (parent::isFrozen()) {
return parent::getFrozenHtml();
}
$attributes = $this->getAttributes();
$this->removeAttribute('show_hide');
$this->_attributes['class'] = ($attributes['class'] ?? '').' p-password-input ';
$input = parent::toHtml();
if (empty($attributes['show_hide'])) {
return $input;
}
$id = $attributes['id'] ?? '';
return '<div class="p-password p-component p-inputwrapper p-inputwrapper-filled p-icon-field p-icon-field-right">
'.$input.'
<span class="p-icon p-input-icon mdi mdi-'.ActionIcon::VISIBLE->value.'"></span>
</div>'
."<script>$('input#$id + .p-icon.mdi').click(() => {
var txtPasswd = $('input#$id')
txtPasswd.attr('type', txtPasswd.attr('type') === 'password' ? 'text' : 'password');
})</script>";
}
}

@ -134,6 +134,8 @@ class HTML_QuickForm_text extends HTML_QuickForm_input
return $this->getFrozenHtml();
}
$attributes = $this->getAttributes();
$this->_attributes['class'] = ($attributes['class'] ?? '').' p-inputtext p-component ';
if (FormValidator::LAYOUT_HORIZONTAL === $this->getLayout()) {

Loading…
Cancel
Save