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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Dropdownfield doesn't set selected item


4 Posts   368 Views


22 March 2013 at 1:29am (Last edited: 22 March 2013 1:29am), Community Member, 81 Posts


I'm trying to insert a DropDownfield into a CMSfield popup in Silverstripe 2.4.

The right value is inserted into the DB after saving. However, the Dropdownfield doesn't stay to the selected item but returns to the first. My code:

class Link extends DataObject{
static $db = array(
'Descript'=> 'Text',
'ExternURL'=> 'Text',
'InternURL'=> 'Varchar'


static $has_one = array(
'Pagina' => 'SiteTree'

public function getCMSFields_forPopup() {
$fields = parent::getCMSFields();
$fields = new FieldSet(
new TextField('Descript', 'Description'),
new TextField('ExternURL', 'External link (including http://)'),
new DropdownField('InternURL','OR Internal link:', DataObject::get("SiteTree")->toDropdownMap('ID', 'Title', '(Select one)', true))

return $fields;

Anyone a solution?


23 March 2013 at 2:32am Community Member, 81 Posts

Found the solution: I got a function "getInternURL()", but that's not possible.


26 March 2013 at 8:10pm Forum Moderator, 5511 Posts

InternURL, your managed DropdownField should rather be in your has_one array if you want to store a relationship between Link and a SiteTree object.

static $has_one = array(
'Pagina' => 'SiteTree',
'InternURL' => 'SiteTree'

new DropdownField('InternURLID','OR Internal link:', DataObject::get("SiteTree")->map('ID', 'Title')))


28 March 2013 at 2:55am Community Member, 81 Posts

Thanks, it works for me! However, it took me an hour to find out the ID after the InternURL.

Even easier now:

$fields->addFieldToTab('Root.Main', new TreeDropdownField('InternURL', 'Link Blok 2', 'SiteTree'));