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.

Form Questions /

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

DropdownField not loading with loadDataFrom()


Go to End


2 Posts   1455 Views

Avatar
allenmccabe

Community Member, 5 Posts

5 February 2013 at 8:00am

I have a custom form for updating a database row. I pre-populate the field values using $form->loadDataFrom( $data ), where $data is an associative array of the field values.

This works great for all but the DropdownField; nothing is set as "selected".

Relevant code:

On the form subclass:

$fields = FieldList::create(
...
DropdownField::create('subscribed')->setSource(array('1' => 'Yes', '0' => 'No'))->setAttribute('class', 'default')
);

In the controller:
$form->loadDataFrom($data);

I have verified that $data is a properly formatted associative array (after all, every other field gets the appropriate value).

The dropdown field will not set a selected value.

Avatar
allenmccabe

Community Member, 5 Posts

9 February 2013 at 6:57am

I ended up switching to Yes/No radio buttons.