I've been trying to set a default value for a CheckboxField, however this doesn't seem to behave the same way as TextareaField and Textfield. I've included a basic working sample below copied and pasted from bits from my actual form.
The textarea and textfields show the default value initially. If I change them and submit the form the changed values are shown. If I uncheck CB1 and check CB2 and submit the form they changes are not retained and their values are reset. I would expect them to keep the latest settings as the default value should only be used the first time as with the other two text fields.
Is it just me missing something or should I report this as a bug?
function TheForm() {
$fields = new FieldSet(
new TextareaField('Textarea','Area', 8, 3, "Text area test"),
new CheckboxField('CB1', 'Checked', 1),
new CheckboxField('CB2', 'Not checked', 0),
new TextField('TextField', 'Textfield test')
);
$actions = new FieldSet(
new FormAction('ProcessForm', 'Process Form')
);
$form = new Form($this, 'MyForm', $fields, $actions, $validator);
if(is_array(Session::get('MyForm'))) {
$form->loadDataFrom(Session::get('MyForm'));
}
return $form;
}
function ProcessForm($data, $form) {
Session::set("MyForm", $data);
return $this->customise($data)->renderWith(array('MyForm', 'Page'));
// Do form stuff
}
MyForm.ss
$Textarea
$CB1
$CB2
$Textfield
$TheForm