- Added new methods for each inputs ui_...; fixed empty or 0 values checkbox/radio checked handling
This commit is contained in:
parent
fd4e30bd42
commit
328a4d282c
|
@ -3,10 +3,9 @@
|
||||||
namespace Picea\Ui\Form;
|
namespace Picea\Ui\Form;
|
||||||
|
|
||||||
use Picea\Ui\Common\UiElement;
|
use Picea\Ui\Common\UiElement;
|
||||||
use Picea\Extension\Extension;
|
use Picea\Extension\{ Extension, FunctionExtension, ExtensionTrait };
|
||||||
use Picea\Extension\ExtensionTrait;
|
|
||||||
|
|
||||||
class UiInput extends UiElement implements Extension {
|
class UiInput extends UiElement implements Extension, FunctionExtension {
|
||||||
use ExtensionTrait;
|
use ExtensionTrait;
|
||||||
|
|
||||||
public string $token = "ui:input";
|
public string $token = "ui:input";
|
||||||
|
@ -19,7 +18,7 @@ class UiInput extends UiElement implements Extension {
|
||||||
'tag-type' => "single",
|
'tag-type' => "single",
|
||||||
];
|
];
|
||||||
|
|
||||||
protected /* ? mixed */ $value;
|
protected mixed $value;
|
||||||
|
|
||||||
protected string $name;
|
protected string $name;
|
||||||
|
|
||||||
|
@ -32,6 +31,19 @@ class UiInput extends UiElement implements Extension {
|
||||||
return "<?php echo ( new \\" . static::class . "() )->buildHtml($arguments) ?>";
|
return "<?php echo ( new \\" . static::class . "() )->buildHtml($arguments) ?>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function exportFunctions(): array
|
||||||
|
{
|
||||||
|
if ( null === $type = $this->attributes['type'] ?? null ) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$key = str_replace('-', '_', 'ui_'. ( $this->attributes['type'] ?? 'text' ));
|
||||||
|
|
||||||
|
return [
|
||||||
|
$key => fn(string $name, mixed $value = null, array $attributes = [], array $options = []) : string => $this->buildHtml($name, $value, $attributes, $options),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function buildHtml(string $name, mixed $value = null, array $attributes = [], array $options = []) : string
|
public function buildHtml(string $name, mixed $value = null, array $attributes = [], array $options = []) : string
|
||||||
{
|
{
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
|
|
|
@ -13,7 +13,7 @@ class UiRadio extends UiInput {
|
||||||
|
|
||||||
protected function objectAttribute() : array
|
protected function objectAttribute() : array
|
||||||
{
|
{
|
||||||
if ( ( $this->options['value'] ?? false ) && ( $this->options['value'] === $this->value ) ) {
|
if ( isset($this->options['value']) && ( $this->options['value'] === $this->value ) ) {
|
||||||
return [
|
return [
|
||||||
'checked' => "checked"
|
'checked' => "checked"
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in New Issue