I have a front end form which requires the selection of a lottery feed using OptionsetField. I need to check the first item by default but I can't get it to work.
Before i go completely bonkers, Is there anyone out there able to set me right please?
Initially this was my field code .
OptionsetField::create('LotteryFeedID', 'LotteryFeed') ->setSource(LotteryFeed::get()->map('ID','Title'))
I attempted defining the source as a variable ($map) outside the FieldList and then calling it as follows; using the api example for OptionsetField:
$map = LotteryFeed::get()->map('ID','Title'); $fields = new FieldList( OptionsetField::create('LotteryFeedID', 'LotteryFeed', $map, $map) );
No error on build this time, but it fails to actually check the first item in the list on the template.
I then attempted to set the default value in the class itself
private static $defaults = array ( 'LotteryFeed' => '' // not sure of the syntax here );
Banging my head against the wall isn't helping, it's no doubt super easy but I cannot find reference to the correct answer.
Thanks in advance