fix
This commit is contained in:
18
src/app/controllers/Main.php
Normal file
18
src/app/controllers/Main.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace itguild\forms\app\controllers;
|
||||
|
||||
class Main
|
||||
{
|
||||
|
||||
public function indexAction(): void
|
||||
{
|
||||
echo 123;
|
||||
}
|
||||
|
||||
public function exampleAction()
|
||||
{
|
||||
echo "example";
|
||||
}
|
||||
|
||||
}
|
@ -6,9 +6,9 @@ use itguild\forms\inputs\Checkbox;
|
||||
|
||||
class CheckBoxBuilder
|
||||
{
|
||||
public static function build(string $name, array $params = [])
|
||||
public static function build(string $name, array $params = []): Checkbox
|
||||
{
|
||||
$value = $params['value'] ?? null;
|
||||
$value = $params['value'] ?? "";
|
||||
unset($params['value']);
|
||||
|
||||
return new Checkbox(name: $name, value: $value, paramsArray: $params);
|
||||
|
@ -10,6 +10,7 @@ abstract class BaseInput
|
||||
protected bool $hasLabel = false;
|
||||
protected string $html = '';
|
||||
protected string|Label $label = "";
|
||||
protected string $labelString = "";
|
||||
|
||||
/**
|
||||
* @return void
|
||||
@ -38,6 +39,18 @@ abstract class BaseInput
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function createLabel()
|
||||
{
|
||||
if($this->hasLabel) {
|
||||
if(is_string($this->label)){
|
||||
$this->labelString = "<label>$this->label</label>";
|
||||
}
|
||||
else {
|
||||
$this->labelString= $this->label->create()->fetch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $template
|
||||
* @return $this
|
||||
|
@ -34,12 +34,12 @@ class Button extends BaseInput
|
||||
{
|
||||
$paramsString = $this->createParams($this->paramsArray);
|
||||
$label = "";
|
||||
$button = "<input type='button' name='$this->name' $paramsString>$this->value";
|
||||
if($this->hasLabel == true) {
|
||||
$label = "<label>$this->labelTitle</label>";
|
||||
}
|
||||
$button = "<input type='button' value='$this->value' name='$this->name' $paramsString>";
|
||||
|
||||
$this->createLabel();
|
||||
|
||||
$this->html = str_replace('{input}', $button, $this->inputTemplate->getInputTemplate());
|
||||
$this->html = str_replace('{label}', $label, $this->html);
|
||||
$this->html = str_replace('{label}', $this->labelString, $this->html);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -37,11 +37,11 @@ class Checkbox extends BaseInput
|
||||
$paramsString = $this->createParams($this->paramsArray);
|
||||
$checkBox = "<input name='$this->name' type='checkbox' value='$this->value' $paramsString >";
|
||||
$label = "";
|
||||
if($this->hasLabel == true) {
|
||||
$label = "<label>$this->labelTitle</label>";
|
||||
}
|
||||
|
||||
$this->createLabel();
|
||||
|
||||
$this->html = str_replace('{input}', $checkBox, $this->inputTemplate->getInputTemplate());
|
||||
$this->html = str_replace('{label}', $label, $this->html);
|
||||
$this->html = str_replace('{label}', $this->labelString, $this->html);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -46,11 +46,11 @@ class Select extends BaseInput
|
||||
$optionsString = $this->createOption($this->options, $this->value);
|
||||
$label = "";
|
||||
$select = "<select name='$this->name' $paramsString>$optionsString</select>";
|
||||
if($this->hasLabel == true) {
|
||||
$label = "<label>$this->labelTitle</label>";
|
||||
}
|
||||
|
||||
$this->createLabel();
|
||||
|
||||
$this->html = str_replace('{input}', $select, $this->inputTemplate->getInputTemplate());
|
||||
$this->html = str_replace('{label}', $label, $this->html);
|
||||
$this->html = str_replace('{label}', $this->labelString, $this->html);
|
||||
|
||||
return $this;
|
||||
|
||||
|
@ -37,12 +37,11 @@ class TextArea extends BaseInput
|
||||
$paramsString = $this->createParams($this->paramsArray);
|
||||
$label = "";
|
||||
$textarea = "<textarea name='$this->name' $paramsString>$this->value</textarea>";
|
||||
if($this->hasLabel == true) {
|
||||
$label = "<label>$this->labelTitle</label>";
|
||||
}
|
||||
|
||||
$this->createLabel();
|
||||
|
||||
$this->html = str_replace('{input}', $textarea, $this->inputTemplate->getInputTemplate());
|
||||
$this->html = str_replace('{label}', $label, $this->html);
|
||||
$this->html = str_replace('{label}', $this->labelString, $this->html);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -38,17 +38,11 @@ class TextInput extends BaseInput
|
||||
$paramsString = $this->createParams($this->paramsArray);
|
||||
$label = "";
|
||||
$input = "<input name='$this->name' $paramsString >";
|
||||
if($this->hasLabel == true) {
|
||||
if(is_string($this->label)){
|
||||
$label = "<label>$this->labelTitle</label>";
|
||||
}
|
||||
else {
|
||||
$label = $this->create()->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
$this->createLabel();
|
||||
|
||||
$this->html = str_replace('{input}', $input, $this->inputTemplate->getInputTemplate());
|
||||
$this->html = str_replace('{label}', $label, $this->html);
|
||||
$this->html = str_replace('{label}', $this->labelString, $this->html);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ namespace itguild\forms\mappers;
|
||||
|
||||
use itguild\forms\builders\Builder;
|
||||
use itguild\forms\builders\ButtonBuilder;
|
||||
use itguild\forms\builders\CheckBoxBuilder;
|
||||
use itguild\forms\builders\LabelBuilder;
|
||||
use itguild\forms\builders\RadioButtonBuilder;
|
||||
use itguild\forms\builders\SelectBuilder;
|
||||
@ -20,7 +21,8 @@ class JsonInputMapper
|
||||
"textArea" => TextAreaBuilder::class,
|
||||
"radio" => RadioButtonBuilder::class,
|
||||
"select" => SelectBuilder::class,
|
||||
"button" => ButtonBuilder::class
|
||||
"button" => ButtonBuilder::class,
|
||||
"checkbox" => CheckBoxBuilder::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user