From 507555e907c1f1399f7e098c8fba6cfa6cb0f813 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 26 May 2017 09:18:35 -0400 Subject: [PATCH] Fix issue processwire/processwire-issues#268 --- wire/modules/Inputfield/InputfieldSelect.module | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/wire/modules/Inputfield/InputfieldSelect.module b/wire/modules/Inputfield/InputfieldSelect.module index 8fdd4457..83731524 100644 --- a/wire/modules/Inputfield/InputfieldSelect.module +++ b/wire/modules/Inputfield/InputfieldSelect.module @@ -66,14 +66,20 @@ class InputfieldSelect extends Inputfield { /** * Add multiple options at once * - * @param array $options May be associative or regular array. If associative, use $value => $label. If regular, - * use just array($value, ...) + * @param array $options Array of options to add. It is assumed that array keys are the option value, and array + * values are the option labels, unless overridden by the $assoc argument. + * @param bool $assoc Is $options an associative array? (default=true). Specify false if $options is intended to be + * a regular PHP array, where the array keys/indexes should be ignored, and option value will also be the label. * @return $this * */ - public function addOptions(array $options) { + public function addOptions(array $options, $assoc = true) { foreach($options as $k => $v) { - $this->addOption($k, $v); + if($assoc) { + $this->addOption($k, $v); + } else { + $this->addOption($v); + } } return $this; }