35 lines
1.4 KiB
PHP
35 lines
1.4 KiB
PHP
<?
|
|
|
|
namespace ui\input;
|
|
|
|
class Select extends Input {
|
|
public function render(array $opt = array()): string{
|
|
$vals = [];
|
|
$sels = is_array($c = $this->options[Input::VALUE]) ? $c : ($c===null?[]:[$c]);
|
|
$this->options[Input::WITHNULLROW]?$vals[] = '<option value="0">Выбрать</option>':'';
|
|
|
|
foreach ($this->options[Input::OPTIONS] as $k=>$v){
|
|
if(is_array($v)){
|
|
$name = $v['name'];
|
|
} else {
|
|
$name = $v;
|
|
}
|
|
$selected = in_array($k,$sels);
|
|
$vals[] = '<option value="'.$k.'" '.($selected?'selected':'').'>'.$name.'</option>';
|
|
|
|
|
|
if ($this->options[Input::ONLY_ADD_VALUE] and $selected and $k > 0){
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(file_exists($file = dirname(__FILE__).'/views/'.$this->theme.'.php')) {
|
|
ob_start();include($file);return ob_get_clean();
|
|
} else {
|
|
return '<div class="form-group" data-input="select" data-name="'.$this->name.'" '.$this->getDataInit().'>
|
|
' . (($c = $this->label) ? '<label>' . $this->label . '</label>' : '') . '
|
|
<select class="form-control select ' . $this->options[Input::CSS_CLASS] . '" name="' . $this->name . '" data-placeholder="' . $this->options[Input::PLACEHOLDER] . '">' . implode($vals) . '</select>
|
|
</div>';
|
|
}
|
|
}
|
|
} |