mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
MINOR Removed overzealous value validation in ListboxField, should silently ignore unknown values (lacking better referential integrity measures in the underlying model layer)
This commit is contained in:
parent
82ef236879
commit
cb74dbccfc
@ -162,18 +162,14 @@ class ListboxField extends DropdownField {
|
|||||||
throw new InvalidArgumentException('No associative arrays allowed multiple=true');
|
throw new InvalidArgumentException('No associative arrays allowed multiple=true');
|
||||||
}
|
}
|
||||||
|
|
||||||
if($diff = array_diff($parts, array_keys($this->source))) {
|
// Doesn't check against unknown values in order to allow for less rigid data handling.
|
||||||
throw new InvalidArgumentException(sprintf(
|
// They're silently ignored and overwritten the next time the field is saved.
|
||||||
'Invalid keys "%s" in value array for multiple=true',
|
|
||||||
Convert::raw2xml(implode(',', $diff))
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::setValue($parts);
|
parent::setValue($parts);
|
||||||
} else {
|
} else {
|
||||||
if(!in_array($val, array_keys($this->source))) {
|
if(!in_array($val, array_keys($this->source))) {
|
||||||
throw new InvalidArgumentException(sprintf(
|
throw new InvalidArgumentException(sprintf(
|
||||||
'Invalid value "%s" for multiple=true',
|
'Invalid value "%s" for multiple=false',
|
||||||
Convert::raw2xml($val)
|
Convert::raw2xml($val)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
@ -90,18 +90,6 @@ class ListboxFieldTest extends SapphireTest {
|
|||||||
$field->setValue('invalid');
|
$field->setValue('invalid');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException InvalidArgumentException
|
|
||||||
*/
|
|
||||||
function testSetValueFailsOnInvalidArrayKeyIfChoiceInvalidAndMultipleIsOn() {
|
|
||||||
$choices = array('a' => 'a value', 'b' => 'b value','c' => 'c value');
|
|
||||||
$field = new ListboxField('Choices', 'Choices', $choices);
|
|
||||||
$field->multiple = true;
|
|
||||||
|
|
||||||
$obj = new ListboxFieldTest_DataObject();
|
|
||||||
$field->setValue(array('a', 'invalid'));
|
|
||||||
}
|
|
||||||
|
|
||||||
function testFieldRenderingMultipleOff() {
|
function testFieldRenderingMultipleOff() {
|
||||||
$choices = array('a' => 'a value', 'b' => 'b value','c' => 'c value');
|
$choices = array('a' => 'a value', 'b' => 'b value','c' => 'c value');
|
||||||
$field = new ListboxField('Choices', 'Choices', $choices);
|
$field = new ListboxField('Choices', 'Choices', $choices);
|
||||||
|
Loading…
Reference in New Issue
Block a user