Jump to:

5542 Posts in 1739 Topics by 1225 members

Customising the CMS

SilverStripe Forums » Customising the CMS » DropdownField - what am I doing wrong?

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

Page: 1
Go to End
Author Topic: 297 Views
  • mundek23
    Avatar
    Community Member
    7 Posts

    DropdownField - what am I doing wrong? Link to this post

    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.

  • Willr
    Avatar
    Forum Moderator
    5508 Posts

    Re: DropdownField - what am I doing wrong? Link to this post

    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.

  • mundek23
    Avatar
    Community Member
    7 Posts

    Re: DropdownField - what am I doing wrong? Link to this post

    Doh, thanks - that works.

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