1779 Posts in 582 Topics by 556 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 303 Views |
-
Setting defaults in CheckboxSetField

10 January 2012 at 5:58am
I've got a form that's part of an 'Edit Profile' type page where the user makes a check box style selection from a list of Capabilities. I'm having problems figuring out what to pass as the last value in the constructor to set the defaults though. Obviously since it's an edit profile page I need the users current selections to show up when they load the page.
Code so far:
$capabilities = DataObject::get('Capability');
$capabilityField = new CheckboxSetField(
'Name',
'Capabilities: ',
$capabilities,
Array(
$testcap->Name
)
);I have tried lots of different formats for the last parameter, including an array of Capability names, an array that looks like 'engines' => '1', an array of integers. What is the correct format to pass for the default array so that I can control which of the checkboxes are ticked?
Any advice appreciated.
Thanks
-
Re: Setting defaults in CheckboxSetField

14 January 2012 at 2:14am
I eventually gave up on this one, and used a series of optionsetfields instead. It was quite easy that way to set the values to '1' or '0'.
Now though, I'm running into the same problem with a DropdownField. I'm trying to set the selected value of the field when the form is loaded but everything I try to set as a default value (eg, '4', 4, $capabilityMap[4], $capabilityMap['4'], Capability objects, titles of capability objects) has zero effect.
Can somebody please point me in the direction of the correct syntax for the $value parameter to get this to work? There are quite a few web pages describing the use of DropdownField, but very few show the $value functionality in use.
$capabilities = DataObject::get('Capability');
$capabilityMap = $capabilities->toDropDownMap('ID','Title');
$capabilityField = new DropdownField(
'capability',
'Main capability requirement',
$capabilityMap,
'4'
); -
Re: Setting defaults in CheckboxSetField

14 January 2012 at 2:48am
Resolved => code was working but was being overwritten by loading data into the form.
| 303 Views | ||
|
Page:
1
|
Go to Top |

