36 lines
1.3 KiB
PHP
36 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace Komponent\Component\Testquestions\Administrator\Field;
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
use Joomla\CMS\Form\Field\PasswordField;
|
|
|
|
class AiapikeyField extends PasswordField
|
|
{
|
|
protected $type = 'Aiapikey';
|
|
|
|
protected function getInput(): string
|
|
{
|
|
$id = htmlspecialchars($this->id, ENT_QUOTES, 'UTF-8');
|
|
$length = mb_strlen((string) $this->value);
|
|
|
|
return '<div class="input-group">'
|
|
. parent::getInput()
|
|
. '<button type="button" class="btn btn-outline-secondary" data-ai-key-toggle="' . $id . '">Pokaż</button>'
|
|
. '</div>'
|
|
. '<small class="form-text text-muted">Klucz: ' . (int) $length . ' znaków.</small>'
|
|
. '<script>
|
|
document.addEventListener("click", function (event) {
|
|
var button = event.target.closest("[data-ai-key-toggle]");
|
|
if (!button) return;
|
|
var input = document.getElementById(button.getAttribute("data-ai-key-toggle"));
|
|
if (!input) return;
|
|
var visible = input.type === "text";
|
|
input.type = visible ? "password" : "text";
|
|
button.textContent = visible ? "Pokaż" : "Ukryj";
|
|
});
|
|
</script>';
|
|
}
|
|
}
|