setHtmlType('password'); $this->getControlPrototype()->appendAttribute('class', self::INPUT_CLASS); } public function getControl(): Html { $input = parent::getControl(); $input->value = $this->getRenderedValue(); $button = Html::el('button') ->setAttribute('type', 'button') ->setAttribute('tabindex', '-1') ->appendAttribute('class', 'btn btn-outline-secondary ' . self::TOGGLE_CLASS) ->addHtml(Html::el('i')->setAttribute('class', 'fas fa-eye')); $group = Html::el('div') ->setAttribute('class', 'input-group') ->addHtml($input) ->addHtml($button) ->addHtml(self::getScript()); return $group; } public static function addPasswordReveal(Container $container, string $name, $label = null): self { $component = new self($label); $container->addComponent($component, $name); return $component; } public static function register(): void { Form::extensionMethod('addPasswordReveal', [self::class, 'addPasswordReveal']); Container::extensionMethod('addPasswordReveal', [self::class, 'addPasswordReveal']); } private static function getScript(): Html { $js = << self::INPUT_CLASS, '{TOGGLE_CLASS}' => self::TOGGLE_CLASS, ]); return Html::el('script')->setHtml($js); } }