37 lines
1.1 KiB
PHP
37 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace itguild\forms\inputs;
|
|
use itguild\forms\inputs\BaseInput;
|
|
class CgSelectInput extends BaseInput
|
|
{
|
|
|
|
private string $selector;
|
|
private array $params;
|
|
private $params;
|
|
public function __construct(string $selector, array $params = [])
|
|
{
|
|
$this->selector = $selector;
|
|
$this->params = $params;
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$paramsString = $this->createParams($this->paramsArray);
|
|
$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->html = str_replace('{input}', $select, $this->inputTemplate->getInputTemplate());
|
|
$this->html = str_replace('{label}', $label, $this->html);
|
|
|
|
return $this;
|
|
}
|
|
|
|
public static function build(string $name, array $options = [], $value = null, array $paramsArray = []): void
|
|
{
|
|
$select = new self($name, $options, $value, $paramsArray);
|
|
$select->create()->render();
|
|
}
|
|
} |