HI all,
Hope someone can point me in the right direction with this problem. I have set up some forms in my front end to add/edit dataobjects. The idea is that with "add" all from fields are editable and with an "edit" only certain fields are editable. When I set some of the fields in the edit form to readonly, those fields get set to NULL/0 after the dataobject->write()... That is incorrect, they should be left alone and keep their original (add) value. This used to work in SS 2.* but readonly's get changed to 0/NULL when I upgraded to 3.
I have a form set up, the standard way:
public function EditForm() {
$fields = $this->currentRecord->getFrontendFields($this->request->param('OtherID'));
$validator = ($this->currentRecord->hasMethod('getValidator')) ? $this->currentRecord->getValidator() : new RequiredFields();
$actions = new FieldList(
new FormAction("doEdit", 'Opslaan')
);
$form = new Form($this, "EditForm", $fields, $actions, $validator);
$form->loadDataFrom($this->currentRecord);
return $form;
}
with a form handler:
function doEdit($data, $form, $request) {
$form->saveInto($this->currentRecord);
$this->currentRecord->write();
return "#".$CSSClassName.$this->currentRecord->ID;
}
When I add a dataobject, all form fields are editable. When a dataobject is edited, only certain fields can be changed. I handle that in the getFrontEndFields of the dataobject. Ie:
function getFrontendFields($actionGroup='edit') {
$VerbruikKwhUrenHoog = new TextField('Verbruik Kwh Uren Hoog','Verbruik Kwh uren hoog(T1)');
$VerbruikKwhUrenLaag = new TextField('Verbruik Kwh Uren Laag','Verbruik Kwh uren laag (T1)');
if( !empty($this->ID) ){
$VerbruikKwhUrenLaag = $VerbruikKwhUrenLaag->performReadonlyTransformation();
}
return new FieldList(
new FieldGroup(
$VerbruikKwhUrenLaag,
$VerbruikKwhUrenHoog
)
);
}
Now after the $this->currentRecord->write() in the doEdit method all the readonly fields are set to 0/NULL. Is this expected behaviour since SS3? Or am I missing something?