diff --git a/include/class.dynamic_forms.php b/include/class.dynamic_forms.php index 8e4df839ad1b12552a3f182be0232923cccf6e63..c22e563fee5ad6f21a2d45e49374ed11f624913a 100644 --- a/include/class.dynamic_forms.php +++ b/include/class.dynamic_forms.php @@ -879,7 +879,9 @@ class SelectionField extends FormField { function parse($value) { $config = $this->getConfiguration(); - if (is_int($value) || !$config['typeahead']) + if (is_int($value)) + return $this->to_php($this->getWidget()->getEnteredValue(), (int) $value); + elseif (!$config['typeahead']) return $this->to_php(null, (int) $value); else return $this->to_php($value); @@ -889,7 +891,7 @@ class SelectionField extends FormField { if ($id && is_int($id)) $item = DynamicListItem::lookup($id); # Attempt item lookup by name too - if (!$item) { + if (!$item || ($value !== null && $value != $item->get('value'))) { $item = DynamicListItem::lookup(array( 'value'=>$value, 'list_id'=>$this->getListId())); @@ -908,9 +910,13 @@ class SelectionField extends FormField { } function validateEntry($item) { + $config = $this->getConfiguration(); parent::validateEntry($item); if ($item && !$item instanceof DynamicListItem) $this->_errors[] = 'Select a value from the list'; + elseif ($item && $config['typeahead'] + && $this->getWidget()->getEnteredValue() != $item->get('value')) + $this->_errors[] = 'Select a value from the list'; } function getConfigurationOptions() { @@ -944,10 +950,8 @@ class SelectionWidget extends ChoicesWidget { } elseif ($this->value) { // Loaded from POST $value = $this->value; - $name = DynamicListItem::lookup($value); - $name = ($name) ? $name->get('value') : $value; + $name = $this->getEnteredValue(); } - if (!$config['typeahead']) { $this->value = $value; return parent::render(); @@ -989,5 +993,10 @@ class SelectionWidget extends ChoicesWidget { return (int) $data[$this->name.'_id']; return parent::getValue(); } + + function getEnteredValue() { + // Used to verify typeahead fields + return parent::getValue(); + } } ?>