Jump to:

3432 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Using DropdownField in the admin

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

Page: 1
Go to End
Author Topic: 1370 Views
  • roterl
    Avatar
    Community Member
    44 Posts

    Using DropdownField in the admin Link to this post

    Hi
    I created some page decoration that one of its field is other page.
    I use the DropdownField to allow the selection of the page. The problem is that the DropdownField indeed display the pages, but it does not save the selected one.

    class MyDecorator extends DataObjectDecorator {

       function extraStatics() {
          return array(
             'db' => array(
                "AAA" => "Varchar(255)",
          ),
             'has_one' => array(
                "MyPage" => "Page",
          ),
          );
       }

       public function updateCMSFields(FieldSet &$fields) {
          $fields->addFieldToTab("Root.Content.PageHolder", new TextField("AAA", "My AAA", "default"));
          $fields->addFieldToTab("Root.Content.PageHolder", new DropdownField('MyPage', 'My Page', Dataobject::get("Page")->toDropdownMap('ID','Title','[From Parent]')));

       }

    ...
    }


    The AAA (which I just add for test if it works) is saved as it should.
    In The MyPage the list of the pages is display correctly, but the selected value isnt saved).

    any ideas,
    Thanks
    Rotem.

  • Martijn
    Avatar
    Community Member
    271 Posts

    Re: Using DropdownField in the admin Link to this post

    The relation is stored in the database with MYPageID.

    This should work:

    $fields->addFieldToTab("Root.Content.PageHolder", new DropdownField('MyPageID', 'My Page', Dataobject::get("Page")->toDropdownMap('ID','Title','[From Parent]')));

  • roterl
    Avatar
    Community Member
    44 Posts

    Re: Using DropdownField in the admin Link to this post

    thanks, that works now.
    Other problem I have now is that for the first time I save a Page I must select MyPage field for the save to success (and cant choose the "[from parent]" one. After the first save, it is possible to select the "[from parent]" one.
    This mean that for each page the user need to select the other than "[from parent]" for the first page, and then if he want the default he should select it again and save again.

    How can I fix that?

    thanks,
    Rotem.

  • roterl
    Avatar
    Community Member
    44 Posts

    Re: Using DropdownField in the admin Link to this post

    Ok, I guess thats happens because of DB mess I made while learning build the module by Try & Error (and I had a lot of Errors... )
    I deleted all the table and reinstall it, and all seems to work now.

    thanks,
    Rotem.

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