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.

Customising the CMS

DropdownField - what am I doing wrong?


Reply

3 Posts   306 Views

Avatar
mundek23

28 May 2013 at 9:16am Community Member, 7 Posts

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

28 May 2013 at 9:34pm Forum Moderator, 5511 Posts

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

18 June 2013 at 2:23pm Community Member, 7 Posts

Doh, thanks - that works.