From 8534feea8a7235aa22f30adb1a5d0ed5570f75e0 Mon Sep 17 00:00:00 2001 From: Nick Sagona Date: Tue, 5 Apr 2016 15:55:11 -0500 Subject: [PATCH] Add better support for datalist values --- src/Element/Input/Datalist.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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)); + } } } }