This commit is contained in:
kali
2024-03-18 17:52:16 +03:00
parent a73c5e8170
commit bd456e6331
15 changed files with 532 additions and 23 deletions

View File

@ -2,7 +2,11 @@
namespace itguild\forms\inputs;
use itguild\forms\debug\Debug;
use itguild\forms\inputs\BaseInput;
use itguild\forms\templates\bootstrap5\Bootstrap5Template;
use itguild\forms\templates\Simple\SimpleTemplate;
use itguild\forms\templates\Template;
use itguild\forms\traits\CreateParams;
class TextInput extends BaseInput
@ -15,6 +19,8 @@ class TextInput extends BaseInput
private string $labelTitle = '';
private array $paramsArray;
private Template $inputTemplate;
/**
* @param string $name
@ -24,6 +30,7 @@ class TextInput extends BaseInput
{
$this->name = $name;
$this->paramsArray = $paramsArray;
$this->inputTemplate = new SimpleTemplate();
}
/**
@ -32,11 +39,15 @@ class TextInput extends BaseInput
public function create(): self
{
$paramsString = $this->createParams($this->paramsArray);
$this->html = "<input name='$this->name' $paramsString >";
$label = "";
$input = "<input name='$this->name' $paramsString >";
if($this->hasLabel == true) {
$this->html = "<label>$this->labelTitle</label> $this->html";
$label = "<label>$this->labelTitle</label>";
}
$this->html = str_replace('{input}', $input, $this->inputTemplate->getInputTemplate());
$this->html = str_replace('{label}', $label, $this->html);
return $this;
}
@ -64,5 +75,16 @@ class TextInput extends BaseInput
return $this;
}
/**
* @param $template
* @return $this
*/
public function setTemplate($template): self
{
$this->inputTemplate = new $template();
return $this;
}
}