myk
myk

Reputation: 73

How to display an OptionsetField with default checked value

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

Answers (1)

Brett Tasker
Brett Tasker

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

Related Questions