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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

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

Setting up a dropdown box in the content tab


Go to End


4 Posts   2742 Views

Avatar
NickJacobs

Community Member, 148 Posts

16 June 2008 at 10:16pm

Hi, I want to have a select box on the Main tab (or on another seperate tab) so I can select from a fixed set of options. I can't seem to find anything that shows me what I need to do to add a select & pass it options. Any suggestions?

Avatar
Willr

Forum Moderator, 5523 Posts

16 June 2008 at 11:03pm

You need to use a Dropdown Field. So you can do something like this (in your getCMSFields method).

/* Will save a value from this array into a 'FavColor' field in the DB */

$options = array("Purple", "Green", "Blue", "Orange");
$fields->addFieldToTab("Root.Content.Main", new DropdownField("FavColor", "Favourite Color", $options));

And / or try and use this method.
http://doc.silverstripe.com/doku.php?id=dropdownfield

Avatar
Blackdog

Community Member, 156 Posts

16 July 2008 at 1:39am

hey Willr, can we do multiple selections that way?

Avatar
Willr

Forum Moderator, 5523 Posts

16 July 2008 at 11:31am

If you want to select more then 1 option in the dropdown at a time you have to use silverstripes TreeMultiSelectDropdown Field - http://doc.silverstripe.com/doku.php?id=treemultiselectfield

I havent used this much - I preferred to use ComplexTableFields for the CMS etc but basically you will need to have a many-many join to whatevers in the dropdown and instead of passing the constructor an array as below (the $options bit) you need to pass it the Object of your many many join