update 0.00000001

This commit is contained in:
kali 2024-03-15 17:54:06 +03:00
parent 5bda1e0525
commit 730dc8c7ac
5 changed files with 85 additions and 7 deletions

View File

@ -38,4 +38,12 @@ $activeForm->field(class: TextInput::class, name: 'bbb', params: [])
$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"]) $activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"])
->setLabel("bbbbb") ->setLabel("bbbbb")
->render();
$activeForm->field(class: Radio::class, name: 'nameee',params: ["style" => "color:RED;display:flex"])
->setLabel("bbbbb")
->render();
$activeForm->field(\itguild\forms\inputs\Select::class, 'ddd', ['value' => 2])
->setOptions(['1' => 'bbb1', '2' => 'vvv3', 3 => 'ggg3', 4 => 'fgfgfgfg4'])
->render(); ->render();

View File

@ -2,8 +2,10 @@
namespace itguild\forms; namespace itguild\forms;
use itguild\forms\builders\SelectBuilder;
use itguild\forms\debug\Debug; use itguild\forms\debug\Debug;
use itguild\forms\inputs\BaseInput; use itguild\forms\inputs\BaseInput;
use itguild\forms\inputs\Select;
class ActiveForm class ActiveForm
{ {
@ -11,21 +13,33 @@ class ActiveForm
public function field($class, string $name, array $params = []) public function field($class, string $name, array $params = [])
{ {
$this->fieldObject = new $class($name, $params); if ($class === Select::class){
$this->fieldObject->create(); $this->fieldObject = SelectBuilder::build($name, $params);
}
else {
$this->fieldObject = new $class($name, $params);
}
return $this; return $this;
} }
public function setLabel(string $title) public function setLabel(string $title): self
{ {
$this->fieldObject->setLabel($title); $this->fieldObject->setLabel($title);
return $this; return $this;
} }
public function setOptions(array $options): self
{
$this->fieldObject->setOptions($options);
return $this;
}
public function render() public function render()
{ {
$this->fieldObject->create();
$this->fieldObject->render(); $this->fieldObject->render();
} }

View File

@ -0,0 +1,21 @@
<?php
namespace itguild\forms\builders;
use itguild\forms\debug\Debug;
use itguild\forms\inputs\Select;
class SelectBuilder
{
public static function build(string $name, array $params = [])
{
$value = $params['value'] ?? null;
unset($params['value']);
$options = $params['options'] ?? [];
unset($params['options']);
return new Select(name: $name, options: $options, value: $value, paramsArray: $params);
}
}

View File

@ -1,14 +1,18 @@
<?php <?php
namespace itguild\forms\inputs; namespace itguild\forms\inputs;
use itguild\forms\traits\CreateOption;
use itguild\forms\traits\CreateParams; use itguild\forms\traits\CreateParams;
use itguild\forms\inputs\BaseInput; use itguild\forms\inputs\BaseInput;
class Radio extends BaseInput class Radio extends BaseInput
{ {
use CreateParams; use CreateParams;
use CreateOption;
private $name; private $name;
private $paramsArray; private $paramsArray;
private $options;
private bool $hasLabel = false;
private string $labelTitle = '';
public function __construct(string $name, array $paramsArray = []) public function __construct(string $name, array $paramsArray = [])
{ {
@ -22,7 +26,9 @@ class Radio extends BaseInput
public function create(): self public function create(): self
{ {
$paramsString = $this->createParams($this->paramsArray); $paramsString = $this->createParams($this->paramsArray);
$this->html = "<input name='$this->name' type='radio' $paramsString>"; $optionsString = $this->createOption($this->options, $this->value);
$this->html = "<label>$this->labelTitle</label> $this->html";
$this->html = "<option name='$this->name' type='radio' $paramsString>$optionsString</option>";
return $this; return $this;
} }
@ -44,7 +50,19 @@ class Radio extends BaseInput
*/ */
public function setLabel(string $title): self public function setLabel(string $title): self
{ {
$this->html = "<label>$title $this->html</label>"; $this->hasLabel = true;
$this->labelTitle = $title;
return $this;
}
/**
* @param $options
* @return $this
*/
public function setOptions($options)
{
$this->options = array_merge($options, $this->options);
return $this; return $this;
} }
} }

View File

@ -2,6 +2,7 @@
namespace itguild\forms\inputs; namespace itguild\forms\inputs;
use itguild\forms\debug\Debug;
use itguild\forms\traits\CreateOption; use itguild\forms\traits\CreateOption;
use itguild\forms\traits\CreateParams; use itguild\forms\traits\CreateParams;
use itguild\forms\inputs\BaseInput; use itguild\forms\inputs\BaseInput;
@ -12,6 +13,9 @@ class Select extends BaseInput
use CreateOption; use CreateOption;
private $name; private $name;
private $options; private $options;
private bool $hasLabel = false;
private string $labelTitle = '';
private $value; private $value;
private $paramsArray; private $paramsArray;
@ -38,6 +42,7 @@ class Select extends BaseInput
$paramsString = $this->createParams($this->paramsArray); $paramsString = $this->createParams($this->paramsArray);
$optionsString = $this->createOption($this->options, $this->value); $optionsString = $this->createOption($this->options, $this->value);
$this->html = "<select name='$this->name' $paramsString>$optionsString</select>"; $this->html = "<select name='$this->name' $paramsString>$optionsString</select>";
$this->html = "<label>$this->labelTitle</label> $this->html";
return $this; return $this;
@ -62,7 +67,19 @@ class Select extends BaseInput
*/ */
public function setLabel(string $title): self public function setLabel(string $title): self
{ {
$this->html = "<label>$title $this->html</label>"; $this->hasLabel = true;
$this->labelTitle = $title;
return $this;
}
/**
* @param $options
* @return $this
*/
public function setOptions($options)
{
$this->options = array_merge($options, $this->options);
return $this; return $this;
} }
} }