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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

DropDownField automatically generated does not set "selected" correctly in popup window

Go to End

3 Posts   1916 Views


Community Member, 47 Posts

17 March 2010 at 8:36am


I am not convinced this question belongs to this section (even though it is happening in a Popup Window) please feel free
to reroute ...

I am using a very simple example to illustrate my question.

On one side, I have an DataObject :

class NavigationCountry extends DataObject {
static $db = array(
'CountryName' => 'Text',

This object is populated with DOM - No problem.

On the other side I have another DataObject

class NavigationEntry extends DataObject {
static $db = array(
'Country' => 'Text',
'Description' => 'HTMLText'
'HighlightFlag' => "Enum('Yes,No','No')"

$fields = new FieldSet( new DropdownField(
'Please choose a country',
Dataobject::get("NavigationCountry")->toDropdownMap("CountryName", "CountryName")

new DropdownField(
'Highlight Flag',
new SimpleTinyMCEField('Description', 'Description')

As you can see , the "Country" field of NavigationEntry is a DropDownField populated by a DataObject::get() on the other
object Country followed by a toDropdownMap().

The object NavigationEntry is managed in the page template by an DataObjectManager ....and it works fine
EXCEPTED that everytime an entry is updated , the DropDownField 'Country' is displayed with the first option selected
NOT the data stored for this entry.

What is strange is that it works correctly for the other DropdownField (HighLightFlag) which is generated with an Enum . I mean
that if I create en entry with "Yes" and edit it, the dropdownList will be set correctly to "Yes" .

Why do the two DropDownField work differently? If there a way to have the "Country" list mark as "selected" the value/index
already stored fro this entry instead of selecting the first value by default?

Hope this is not too confusing.
Any help or advice appreciated .

Thanks - Lise


Forum Moderator, 4102 Posts

17 March 2010 at 10:06am

Is there any chance you have another field named "Country" that is colliding with the dropdown? That's the only time I've seen this happen. Try changing the name of the field in both the database and in the form.


Community Member, 47 Posts

17 March 2010 at 1:03pm

Thanks a lot. I changed the name as you said and the problem got fixed. Then I changed it back and it reappeared . Then I
deleted the whole table + recreated it with the initial name (Country) and it is working fine now.
I am sorry I didn't think of trying this before posting. I thought the problem was in my code.

Thanks again for your prompt reply - Very much appreciated.