update 0.00000001
This commit is contained in:
parent
5bda1e0525
commit
730dc8c7ac
@ -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"])
|
||||
->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();
|
@ -2,8 +2,10 @@
|
||||
|
||||
namespace itguild\forms;
|
||||
|
||||
use itguild\forms\builders\SelectBuilder;
|
||||
use itguild\forms\debug\Debug;
|
||||
use itguild\forms\inputs\BaseInput;
|
||||
use itguild\forms\inputs\Select;
|
||||
|
||||
class ActiveForm
|
||||
{
|
||||
@ -11,21 +13,33 @@ class ActiveForm
|
||||
|
||||
public function field($class, string $name, array $params = [])
|
||||
{
|
||||
$this->fieldObject = new $class($name, $params);
|
||||
$this->fieldObject->create();
|
||||
if ($class === Select::class){
|
||||
$this->fieldObject = SelectBuilder::build($name, $params);
|
||||
}
|
||||
else {
|
||||
$this->fieldObject = new $class($name, $params);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setLabel(string $title)
|
||||
public function setLabel(string $title): self
|
||||
{
|
||||
$this->fieldObject->setLabel($title);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOptions(array $options): self
|
||||
{
|
||||
$this->fieldObject->setOptions($options);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->fieldObject->create();
|
||||
$this->fieldObject->render();
|
||||
}
|
||||
|
||||
|
21
src/builders/SelectBuilder.php
Normal file
21
src/builders/SelectBuilder.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
@ -1,14 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\inputs;
|
||||
use itguild\forms\traits\CreateOption;
|
||||
use itguild\forms\traits\CreateParams;
|
||||
use itguild\forms\inputs\BaseInput;
|
||||
class Radio extends BaseInput
|
||||
{
|
||||
use CreateParams;
|
||||
|
||||
use CreateOption;
|
||||
private $name;
|
||||
private $paramsArray;
|
||||
private $options;
|
||||
private bool $hasLabel = false;
|
||||
private string $labelTitle = '';
|
||||
|
||||
public function __construct(string $name, array $paramsArray = [])
|
||||
{
|
||||
@ -22,7 +26,9 @@ class Radio extends BaseInput
|
||||
public function create(): self
|
||||
{
|
||||
$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;
|
||||
}
|
||||
@ -44,7 +50,19 @@ class Radio extends BaseInput
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace itguild\forms\inputs;
|
||||
|
||||
use itguild\forms\debug\Debug;
|
||||
use itguild\forms\traits\CreateOption;
|
||||
use itguild\forms\traits\CreateParams;
|
||||
use itguild\forms\inputs\BaseInput;
|
||||
@ -12,6 +13,9 @@ class Select extends BaseInput
|
||||
use CreateOption;
|
||||
private $name;
|
||||
private $options;
|
||||
|
||||
private bool $hasLabel = false;
|
||||
private string $labelTitle = '';
|
||||
private $value;
|
||||
private $paramsArray;
|
||||
|
||||
@ -38,6 +42,7 @@ class Select extends BaseInput
|
||||
$paramsString = $this->createParams($this->paramsArray);
|
||||
$optionsString = $this->createOption($this->options, $this->value);
|
||||
$this->html = "<select name='$this->name' $paramsString>$optionsString</select>";
|
||||
$this->html = "<label>$this->labelTitle</label> $this->html";
|
||||
|
||||
return $this;
|
||||
|
||||
@ -62,7 +67,19 @@ class Select extends BaseInput
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user