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.

Customising the CMS /

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

DropdownField - what am I doing wrong?


Go to End


3 Posts   942 Views

Avatar
mundek23

Community Member, 7 Posts

28 May 2013 at 9:16am

Hi,

I'm trying to add a custom dropdown field to the CMS:

<?php
class NewsStory extends Page {
static $db = array(
'Author' => 'Text', <---- this works fine
'Color' => "Enum('Red, Blue, Green','Red')"
);

$fields->addFieldToTab('Root.Main', new DropdownField('Color', 'Your favorite color?'), singleton('NewsStory')->dbObject('Color')->enumValues() );

This doesn't seem to work. Any tips greatly received!

Thanks.

Avatar
Willr

Forum Moderator, 5523 Posts

28 May 2013 at 9:34pm

You have a bracket too early from the code you posted.

$fields->addFieldToTab('Root.Main', new DropdownField('Color', 'Your favorite color?', $this->dbObject('Color')->enumValues());

Apart from that, make sure you've run a dev/build so SilverStripe can save the field to Color column.

Avatar
mundek23

Community Member, 7 Posts

18 June 2013 at 2:23pm

Doh, thanks - that works.