1042 Posts in 378 Topics by 372 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 175 Views |
-
Form with readonly-fields overwriting existing values

14 March 2013 at 12:14am
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?
-
Re: Form with readonly-fields overwriting existing values

20 March 2013 at 8:39pm
Sounds like a 'feature' that wasn't documented in 2.* and has been removed. If a field is a Readonly field it shouldn't update the object. Perhaps raise a ticket to open.silverstripe.org.
-
Re: Form with readonly-fields overwriting existing values

19 April 2013 at 8:51am
Hmmm... I was afraid of that. Let me find a clean test-case and possibly raise a ticket.
| 175 Views | ||
|
Page:
1
|
Go to Top |


