Skip to content

Commit

Permalink
feat: readonly state for text input
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasMaros committed Jan 11, 2024
1 parent 64ee686 commit 7692dce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/Input/TextInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,24 @@ class TextInput extends Input

protected $required = false;

protected $readonly = false;

protected const type = 'text';

public function __construct(
MetaForms $metaForms,
string $name = '',
string $label = '',
$value = '',
bool $required = false
bool $required = false,
bool $readonly = false
) {
$this->setMetaForms($metaForms);
$this->setName($name);
$this->setLabel($label);
$this->setValue($value);
$this->setRequired($required);
$this->setReadonly($readonly);
}

/**
Expand Down Expand Up @@ -123,6 +127,16 @@ public function setRequired(bool $required): TextInput
return $this;
}

public function isReadonly(): bool
{
return $this->readonly;
}

public function setReadonly(bool $readonly): void
{
$this->readonly = $readonly;
}

public function render(): void
{
if (empty($this->name) || empty($this->label)) {
Expand Down
4 changes: 3 additions & 1 deletion templates/input-field-text.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class="components-base-control__label"
name="<?= $input->getName() ?>"
id="<?= $input->getName() ?>-input"
class="components-text-control__input"
value="<?= esc_attr($input->getValue()) ?>"<?php if ($input->isRequired()) echo ' required'; ?>
value="<?= esc_attr($input->getValue()) ?>"<?php if ($input->isRequired()) echo ' required'; ?><?php
if ($input->isReadonly()) { echo " readonly"; }
?>
>
</div>
</div>
Expand Down

0 comments on commit 7692dce

Please sign in to comment.