Jump to:

1969 Posts in 1272 Topics by 606 members

Form Questions

SilverStripe Forums » Form Questions » DropdownField not loading with loadDataFrom()

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

Page: 1
Go to End
Author Topic: 426 Views
  • allenmccabe
    Avatar
    Community Member
    5 Posts

    DropdownField not loading with loadDataFrom() Link to this post

    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.

  • allenmccabe
    Avatar
    Community Member
    5 Posts

    Re: DropdownField not loading with loadDataFrom() Link to this post

    I ended up switching to Yes/No radio buttons.

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