Hi
I have a form that's generated by making a FieldSet and adding a new CheckboxField to it, among other inputs, in a particular action function in one of my controllers.
Edit: I want to set a checkbox as checked when the property it represents is true, and unchecked otherwise.
e.g.
class RadioPage_Controller extends Controller {
public function getConfigForm() {
$radio = ...
$fields = new FieldSet();
$bassBoostCheckboxField = $radio->getFrontendFields()->fieldByName('BassBoost');
$fields->push($BassBoostCheckboxField);
}
The form is used to edit properties of an object, and their values are filled in when the form is generated (e.g. name, color, etc not shown)
Setting the value for the CheckboxField sets its value, but doesn't result in it being checked when shown in the browser.
$bassBoostCheckboxField->setAttribute('checked', 'checked')
gives some error, I can't remember what now. The CAUTION in http://api.silverstripe.org/trunk/forms/core/FormField.html#methodsetAttribute doesn't seem like it ought to apply since it's not mentioned and it's only one form field.
This doesn't work if I just create a brand new CheckboxField using its constructor either.
How can I conditionally set a CheckboxField as checked? Is the way I'm making and showing my form the "wrong way" when it represents a subset of the fields of an object?