Skip to content

Commit e7f8f85

Browse files
committed
Add Datalist to HtmlInput
1 parent 2672cd2 commit e7f8f85

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

Ajax/semantic/html/elements/HtmlInput.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,26 @@
1010
use Ajax\JsUtils;
1111
use Ajax\common\html\html5\HtmlInput as HtmlInput5;
1212
use Ajax\service\Javascript;
13+
use Ajax\semantic\html\elements\html5\HtmlDatalist;
1314

1415
class HtmlInput extends HtmlSemDoubleElement {
1516
use IconTrait,TextFieldsTrait,FieldTrait;
1617

17-
public function __construct($identifier, $type="text", $value="", $placeholder="") {
18+
public function __construct($identifier, $type = "text", $value = "", $placeholder = "") {
1819
parent::__construct("div-" . $identifier, "div", "ui input");
19-
$this->_identifier=$identifier;
20-
$this->_libraryId=$identifier;
21-
$this->content=[ "field" => new HtmlInput5($identifier, $type, $value, $placeholder) ];
22-
$this->_states=[ State::DISABLED,State::FOCUS,State::ERROR ];
23-
$this->_variations=[ Variation::TRANSPARENT ];
20+
$this->_identifier = $identifier;
21+
$this->_libraryId = $identifier;
22+
$this->content = [
23+
"field" => new HtmlInput5($identifier, $type, $value, $placeholder)
24+
];
25+
$this->_states = [
26+
State::DISABLED,
27+
State::FOCUS,
28+
State::ERROR
29+
];
30+
$this->_variations = [
31+
Variation::TRANSPARENT
32+
];
2433
}
2534

2635
public function getField() {
@@ -31,27 +40,35 @@ public function getDataField() {
3140
return $this->content["field"];
3241
}
3342

34-
public static function outline($identifier, $icon, $value="", $placeholder="") {
35-
$result=new HtmlInput($identifier, "text", $value, $placeholder);
43+
public static function outline($identifier, $icon, $value = "", $placeholder = "") {
44+
$result = new HtmlInput($identifier, "text", $value, $placeholder);
3645
$result->addToProperty("class", "transparent");
3746
$result->addIcon($icon)->setOutline();
3847
return $result;
3948
}
4049

4150
public function run(JsUtils $js) {
42-
$result=parent::run($js);
43-
$result->attach("#" . $this->getDataField()->getIdentifier());
51+
$result = parent::run($js);
52+
$result->attach("#" . $this->getDataField()
53+
->getIdentifier());
4454
return $result;
4555
}
4656

47-
public function setTransparent(){
57+
public function setTransparent() {
4858
return $this->addToProperty("class", "transparent");
4959
}
50-
51-
public function compile_once(\Ajax\JsUtils $js = NULL, &$view = NULL){
52-
parent::compile_once($js,$view);
53-
if(isset($this->content['file'])){
60+
61+
public function compile_once(\Ajax\JsUtils $js = NULL, &$view = NULL) {
62+
parent::compile_once($js, $view);
63+
if (isset($this->content['file'])) {
5464
$this->onCreate(Javascript::fileUploadBehavior($this->identifier));
5565
}
5666
}
67+
68+
public function addDataList($items) {
69+
$dl = new HtmlDatalist('list-' . $this->identifier);
70+
$dl->addItems($items);
71+
$this->getDataField()->setProperty('list', $dl->getIdentifier());
72+
$this->getDataField()->wrap($dl);
73+
}
5774
}

0 commit comments

Comments
 (0)