Jump to:

2012 Posts in 1438 Topics by 621 members

Form Questions

SilverStripe Forums » Form Questions » Set default value on dynamic DropdownField

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

Page: 1
Go to End
Author Topic: 3946 Views
  • Aram
    Avatar
    Community Member
    598 Posts

    Set default value on dynamic DropdownField Link to this post

    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

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Set default value on dynamic DropdownField Link to this post

    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....

  • UncleCheese
    Avatar
    4085 Posts

    Re: Set default value on dynamic DropdownField Link to this post

    Aram,

    Where is the value of $value coming from?

  • Aram
    Avatar
    Community Member
    598 Posts

    Re: Set default value on dynamic DropdownField Link to this post

    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.

    3946 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.