diff --git a/src/Element/Input/Datalist.php b/src/Element/Input/Datalist.php index 443df86..1793d85 100644 --- a/src/Element/Input/Datalist.php +++ b/src/Element/Input/Datalist.php @@ -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)); + } } } }