Add AI key visibility toggle
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Komponent\Component\Testquestions\Administrator\Field;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Form\FormField;
|
||||
|
||||
class AiapikeyField extends FormField
|
||||
{
|
||||
protected $type = 'Aiapikey';
|
||||
|
||||
protected function getInput(): string
|
||||
{
|
||||
$id = htmlspecialchars($this->id, ENT_QUOTES, 'UTF-8');
|
||||
$name = htmlspecialchars($this->name, ENT_QUOTES, 'UTF-8');
|
||||
$value = htmlspecialchars((string) $this->value, ENT_QUOTES, 'UTF-8');
|
||||
$length = mb_strlen((string) $this->value);
|
||||
|
||||
return '<div class="input-group">'
|
||||
. '<input type="password" id="' . $id . '" name="' . $name . '" value="' . $value . '" size="120" autocomplete="off" class="form-control">'
|
||||
. '<button type="button" class="btn btn-outline-secondary" data-ai-key-toggle="' . $id . '">Pokaż</button>'
|
||||
. '</div>'
|
||||
. '<small class="form-text text-muted">Zapisany 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>';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user