1 | <?php |
||
15 | class HtmlSelect extends HtmlDoubleElement { |
||
16 | private $default; |
||
17 | private $options; |
||
18 | |||
19 | public function __construct($identifier, $caption,$default=NULL) { |
||
20 | parent::__construct($identifier, "select"); |
||
21 | $this->setProperty("name", $identifier); |
||
22 | $this->setProperty("class", "form-control"); |
||
23 | $this->setProperty("value", ""); |
||
24 | $this->default=$default; |
||
25 | $this->options=array(); |
||
26 | } |
||
27 | |||
28 | public function addOption($element,$value="",$selected=false){ |
||
39 | |||
40 | public function setValue($value) { |
||
41 | foreach ( $this->options as $option ) { |
||
42 | if (strcasecmp($option->getValue(),$value)===0) { |
||
43 | $option->setProperty("selected", ""); |
||
44 | } |
||
45 | } |
||
46 | $this->setProperty("value", $value); |
||
47 | } |
||
48 | |||
49 | /* |
||
50 | * (non-PHPdoc) |
||
51 | * @see \Ajax\bootstrap\html\base\BaseHtml::compile() |
||
52 | */ |
||
53 | public function compile(JsUtils $js=NULL, View $view=NULL) { |
||
54 | $this->content=array(); |
||
55 | if(isset($this->default)){ |
||
56 | $default=new HtmlOption("", $this->default); |
||
57 | $this->content[]=$default; |
||
58 | } |
||
59 | foreach ($this->options as $option){ |
||
60 | $this->content[]=$option; |
||
61 | } |
||
62 | return parent::compile($js, $view); |
||
63 | } |
||
64 | |||
65 | public function fromArray($array){ |
||
77 | |||
78 | /* |
||
79 | * (non-PHPdoc) |
||
80 | * @see \Ajax\bootstrap\html\base\HtmlSingleElement::run() |
||
81 | */ |
||
82 | public function run(JsUtils $js) { |
||
83 | parent::run($js); |
||
84 | $this->_bsComponent=$js->bootstrap()->generic("#".$this->identifier); |
||
85 | $this->addEventsOnRun($js); |
||
86 | return $this->_bsComponent; |
||
87 | } |
||
88 | |||
89 | public function onChange($jsCode) { |
||
92 | |||
93 | public function onKeypress($jsCode) { |
||
96 | |||
97 | /* (non-PHPdoc) |
||
98 | * @see \Ajax\bootstrap\html\base\BaseHtml::fromDatabaseObject() |
||
99 | */ |
||
100 | public function fromDatabaseObject($object, $function) { |
||
103 | |||
104 | public function setSize($size){ |
||
105 | return $this->setProperty("size", $size); |
||
106 | } |
||
107 | } |
||
108 |