Reputation: 73
I was checking previous questions but I couldn't find any answer for this. For example I have a field called Gender with 2 selections. How can I set male as selected by default.
Upvotes: 0
Views: 414
Reputation: 219
You can pass a "Value" in the constructor for setting the default "key". http://api.silverstripe.org/3/OptionsetField.html#method___construct
$field = new OptionsetField(
$name = 'Optionfield',
$title = 'My Option Field',
$source = array(
'Option1' => 'Value1',
'Option2' => 'Value2'
),
$default = 'Option1'
)
Upvotes: 1