update 3
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
|
||||
namespace itguild\forms\inputs;
|
||||
|
||||
use itguild\forms\templates\Simple\SimpleTemplate;
|
||||
use itguild\forms\traits\CreateParams;
|
||||
use itguild\forms\inputs\BaseInput;
|
||||
|
||||
@ -12,8 +13,7 @@ class Checkbox extends BaseInput
|
||||
private string $name;
|
||||
private string $value;
|
||||
private array $paramsArray;
|
||||
private bool $hasLabel = false;
|
||||
private string $labelTitle = '';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -21,11 +21,12 @@ class Checkbox extends BaseInput
|
||||
* @param string $value
|
||||
* @param array $paramsArray
|
||||
*/
|
||||
public function __construct(string $name, string $value, array $paramsArray = [])
|
||||
public function __construct(string $name, string $value = '', array $paramsArray = [])
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->value = $value;
|
||||
$this->paramsArray = $paramsArray;
|
||||
$this->inputTemplate = new SimpleTemplate();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,10 +35,13 @@ class Checkbox extends BaseInput
|
||||
public function create(): self
|
||||
{
|
||||
$paramsString = $this->createParams($this->paramsArray);
|
||||
$this->html = "<input name='$this->name' type='checkbox' value='$this->value' $paramsString >";
|
||||
$checkBox = "<input name='$this->name' type='checkbox' value='$this->value' $paramsString >";
|
||||
$label = "";
|
||||
if($this->hasLabel == true) {
|
||||
$this->html = "<label>$this->labelTitle</label> $this->html";
|
||||
$label = "<label>$this->labelTitle</label>";
|
||||
}
|
||||
$this->html = str_replace('{input}', $checkBox, $this->inputTemplate->getInputTemplate());
|
||||
$this->html = str_replace('{label}', $label, $this->html);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -50,20 +54,8 @@ class Checkbox extends BaseInput
|
||||
*/
|
||||
public static function build(string $name, string $value, array $paramsArray): void
|
||||
{
|
||||
$checkbox = new self($name, $value, $paramsArray);
|
||||
$checkbox->create()->render();
|
||||
$checkBox = new self($name, $value, $paramsArray);
|
||||
$checkBox->create()->render();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @return $this
|
||||
*/
|
||||
public function setLabel(string $title): self
|
||||
{
|
||||
$this->hasLabel = true;
|
||||
$this->labelTitle = $title;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user