From 730dc8c7ac18c66703fe0670471485b221e7a1d1 Mon Sep 17 00:00:00 2001 From: kali Date: Fri, 15 Mar 2024 17:54:06 +0300 Subject: [PATCH] update 0.00000001 --- index.php | 8 ++++++++ src/ActiveForm.php | 20 +++++++++++++++++--- src/builders/SelectBuilder.php | 21 +++++++++++++++++++++ src/inputs/Radio.php | 24 +++++++++++++++++++++--- src/inputs/Select.php | 19 ++++++++++++++++++- 5 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 src/builders/SelectBuilder.php diff --git a/index.php b/index.php index 4bd2cea..8c24192 100644 --- a/index.php +++ b/index.php @@ -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(); \ No newline at end of file diff --git a/src/ActiveForm.php b/src/ActiveForm.php index 6118d52..3caa6a1 100644 --- a/src/ActiveForm.php +++ b/src/ActiveForm.php @@ -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(); } diff --git a/src/builders/SelectBuilder.php b/src/builders/SelectBuilder.php new file mode 100644 index 0000000..2f9a475 --- /dev/null +++ b/src/builders/SelectBuilder.php @@ -0,0 +1,21 @@ +createParams($this->paramsArray); - $this->html = ""; + $optionsString = $this->createOption($this->options, $this->value); + $this->html = " $this->html"; + $this->html = ""; return $this; } @@ -44,7 +50,19 @@ class Radio extends BaseInput */ public function setLabel(string $title): self { - $this->html = ""; + $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; } } \ No newline at end of file diff --git a/src/inputs/Select.php b/src/inputs/Select.php index 317a454..9fb67c8 100644 --- a/src/inputs/Select.php +++ b/src/inputs/Select.php @@ -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 = ""; + $this->html = " $this->html"; return $this; @@ -62,7 +67,19 @@ class Select extends BaseInput */ public function setLabel(string $title): self { - $this->html = ""; + $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; } } \ No newline at end of file