Merge pull request #4106 from patricknelson/issue-4104-listboxfield-errors

FIX for #4104, minor revision of error messages in ListboxField (more intuitive).
This commit is contained in:
Ingo Schommer 2015-04-26 17:08:21 +12:00
commit cb7b8b9cdf

View File

@ -215,13 +215,14 @@ class ListboxField extends DropdownField {
if($val) { if($val) {
if(!$this->multiple && is_array($val)) { if(!$this->multiple && is_array($val)) {
throw new InvalidArgumentException('No array values allowed with multiple=false'); throw new InvalidArgumentException('Array values are not allowed (when multiple=false).');
} }
if($this->multiple) { if($this->multiple) {
$parts = (is_array($val)) ? $val : preg_split("/ *, */", trim($val)); $parts = (is_array($val)) ? $val : preg_split("/ *, */", trim($val));
if(ArrayLib::is_associative($parts)) { if(ArrayLib::is_associative($parts)) {
throw new InvalidArgumentException('No associative arrays allowed multiple=true'); // This is due to the possibility of accidentally passing an array of values (as keys) and titles (as values) when only the keys were intended to be saved.
throw new InvalidArgumentException('Associative arrays are not allowed as values (when multiple=true), only indexed arrays.');
} }
// Doesn't check against unknown values in order to allow for less rigid data handling. // Doesn't check against unknown values in order to allow for less rigid data handling.