diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 776f1b3e411b47ff5d0334969080e3fb16fca88b..d97e4b348683f47c6a1f6c9ac71668d303b9261c 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -1326,12 +1326,20 @@ class SelectionField extends FormField { $config = $this->getConfiguration(); $choices = $this->getChoices(); $selection = array(); + + if ($value && !is_array($value)) + $value = array($value); + if ($value && is_array($value)) { foreach ($value as $k=>$v) { - if (($i=$list->getItem((int) $k))) + if ($k && ($i=$list->getItem((int) $k))) $selection[$i->getId()] = $i->getValue(); elseif (isset($choices[$k])) $selection[$k] = $choices[$k]; + elseif (isset($choices[$v])) + $selection[$v] = $choices[$v]; + elseif (($i=$list->getItem($v, true))) + $selection[$i->getId()] = $i->getValue(); } } elseif($value) { //Assume invalid textbox input to be validated diff --git a/include/class.list.php b/include/class.list.php index 843eee44698d089ffc8de1a45eb9e0c02d072514..12d2a85565a4062c4f8c24aca91ada5378bfd404 100644 --- a/include/class.list.php +++ b/include/class.list.php @@ -227,17 +227,18 @@ class DynamicList extends VerySimpleModel implements CustomList { return $this->_items; } - - - function getItem($val) { + function getItem($val, $extra=false) { $items = DynamicListItem::objects()->filter( array('list_id' => $this->getId())); if (is_int($val)) $items->filter(array('id' => $val)); + elseif ($extra) + $items->filter(array('extra' => $val)); else - $items->filter(Q::any(array('value'=>$val, 'extra' => $val))); + $items->filter(array('value' => $val)); + return $items->first(); }