Skip to content
Snippets Groups Projects
Commit 0a6ad37a authored by Peter Rotich's avatar Peter Rotich Committed by Peter Rotich
Browse files

temp: Support abbrev. on selection fields

This is a temporary patch for v1.9.7 -- develop-next already has a better
implementation.
parent 5c7a37a6
No related branches found
No related tags found
No related merge requests found
...@@ -1326,12 +1326,20 @@ class SelectionField extends FormField { ...@@ -1326,12 +1326,20 @@ class SelectionField extends FormField {
$config = $this->getConfiguration(); $config = $this->getConfiguration();
$choices = $this->getChoices(); $choices = $this->getChoices();
$selection = array(); $selection = array();
if ($value && !is_array($value))
$value = array($value);
if ($value && is_array($value)) { if ($value && is_array($value)) {
foreach ($value as $k=>$v) { foreach ($value as $k=>$v) {
if (($i=$list->getItem((int) $k))) if ($k && ($i=$list->getItem((int) $k)))
$selection[$i->getId()] = $i->getValue(); $selection[$i->getId()] = $i->getValue();
elseif (isset($choices[$k])) elseif (isset($choices[$k]))
$selection[$k] = $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) { } elseif($value) {
//Assume invalid textbox input to be validated //Assume invalid textbox input to be validated
......
...@@ -227,17 +227,18 @@ class DynamicList extends VerySimpleModel implements CustomList { ...@@ -227,17 +227,18 @@ class DynamicList extends VerySimpleModel implements CustomList {
return $this->_items; return $this->_items;
} }
function getItem($val, $extra=false) {
function getItem($val) {
$items = DynamicListItem::objects()->filter( $items = DynamicListItem::objects()->filter(
array('list_id' => $this->getId())); array('list_id' => $this->getId()));
if (is_int($val)) if (is_int($val))
$items->filter(array('id' => $val)); $items->filter(array('id' => $val));
elseif ($extra)
$items->filter(array('extra' => $val));
else else
$items->filter(Q::any(array('value'=>$val, 'extra' => $val))); $items->filter(array('value' => $val));
return $items->first(); return $items->first();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment