Fixed loadDataFrom for CheckboxSetFields that are used to edit a many-many relation, if loadBlanks is set to true

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@62641 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-09-18 02:50:14 +00:00
parent 6b6209019c
commit 442af1a7ca

View File

@ -107,6 +107,20 @@ class CheckboxSetField extends OptionsetField {
$this->disabled = $val; $this->disabled = $val;
} }
/**
* Load a value into this CheckboxSetField
*/
function setValue($value, $obj) {
// If we're not passed a value directly, we can look for it in a relation method on the object passed as a second arg
if(!$value && $obj instanceof DataObject && $obj->hasMethod($this->name)) {
$funcName = $this->name;
$selected = $obj->$funcName();
$value = $selected->toDropdownMap('ID','ID');
}
parent::setValue($value, $obj);
}
/** /**
* Save the current value of this CheckboxSetField into a DataObject. * Save the current value of this CheckboxSetField into a DataObject.
* If the field it is saving to is a has_many or many_many relationship, * If the field it is saving to is a has_many or many_many relationship,