| 1 |
<?php if (! defined('ABSPATH')) exit; // Exit if accessed directly |
| 2 |
class HC3_Ui_Element_Input_Select extends HC3_Ui_Abstract_Input |
| 3 |
{ |
| 4 |
protected $el = 'select'; |
| 5 |
protected $uiType = 'input/select'; |
| 6 |
|
| 7 |
protected $options = array(); |
| 8 |
|
| 9 |
public function __construct( $htmlFactory, $name, $label = NULL, $options = array(), $value = NULL ) |
| 10 |
{ |
| 11 |
parent::__construct( $htmlFactory, $name, $label, $value ); |
| 12 |
$this->options = $options; |
| 13 |
} |
| 14 |
|
| 15 |
public function render() |
| 16 |
{ |
| 17 |
$options = array(); |
| 18 |
foreach( $this->options as $k => $v ){ |
| 19 |
if( ! strlen($k) ){ |
| 20 |
$k = ' '; |
| 21 |
} |
| 22 |
|
| 23 |
$this_input = $this->htmlFactory->makeElement('option', $v) |
| 24 |
->addAttr('value', $k ) |
| 25 |
; |
| 26 |
|
| 27 |
if( $k == $this->value ){ |
| 28 |
$this_input |
| 29 |
->addAttr('selected', 'selected') |
| 30 |
; |
| 31 |
} |
| 32 |
$options[] = $this_input; |
| 33 |
} |
| 34 |
|
| 35 |
$options = $this->htmlFactory->makeCollection( $options ); |
| 36 |
|
| 37 |
$out = $this->htmlFactory->makeElement('select', $options) |
| 38 |
->addAttr('name', $this->htmlName() ) |
| 39 |
->addAttr('class', 'hc-field') |
| 40 |
// ->addAttr('class', 'hc-block') |
| 41 |
->addAttr('class', 'hc-full-width') |
| 42 |
; |
| 43 |
|
| 44 |
if( strlen($this->label) ){ |
| 45 |
$out = $this->htmlFactory->makeLabelled( $this->label, $out, $this->htmlId() ); |
| 46 |
} |
| 47 |
|
| 48 |
return $out; |
| 49 |
} |
| 50 |
} |