Skip to content

Commit

Permalink
Add better support for datalist values
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksagona committed Apr 5, 2016
1 parent 9a47a09 commit 8534fee
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Element/Input/Datalist.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ public function __construct($name, array $values, $value = null, $indent = null)
if (null !== $values) {
$this->datalist = new Child('datalist', null, null, $this->indent);
$this->datalist->setAttribute('id', $name . '_datalist');
foreach ($values as $val) {
$this->datalist->addChild((new Child('option'))->setAttribute('value', $val));
foreach ($values as $key => $val) {
if (is_numeric($key)) {
$this->datalist->addChild((new Child('option'))->setAttribute('value', $val));
} else {
$this->datalist->addChild((new Child('option', $val))->setAttribute('value', $key));
}
}
}
}
Expand Down

0 comments on commit 8534fee

Please sign in to comment.