Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Set default value on dynamic DropdownField


Go to End


4 Posts   5974 Views

Avatar
Carbon Crayon

Community Member, 598 Posts

7 February 2009 at 2:13am

Hi Guys

I am trying to set the default value of a dropdown which is generated from the ->toDropdownMap function, but it doesnt seem to work. Here is my code:

new DropdownField('Service', 'Service', Dataobject::get("ServicePage")->toDropdownMap("ID", "Title"), $value=15)

The default just remains as the first Item in the list. I noticed the isSelected() function in the api docs, but I'm not sure where to call that if it's what I need?

Any help is much appreciated :)

Avatar
Carbon Crayon

Community Member, 598 Posts

7 February 2009 at 6:52am

OK, I'm being a muppet, this does work, but doesn't change when you hit refresh, gotta load the page by revisiting the URL....

Avatar
UncleCheese

Forum Moderator, 4102 Posts

7 February 2009 at 7:18am

Aram,

Where is the value of $value coming from?

Avatar
Carbon Crayon

Community Member, 598 Posts

7 February 2009 at 7:34am

Edited: 07/02/2009 7:36am

it being passed into the page via the URL, it's the ID of the page the user clicked through to get to the form.

It's for a quote page, each service provided by the client has a page with a get quote button, so if you click it then it takes you to the quote form which has the service type drop down pre-populated.