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.

Data Model Questions /

Using DropdownField in the admin


Reply


4 Posts   1458 Views

Avatar
roterl

Community Member, 44 Posts

5 December 2009 at 12:37am

Edited: 05/12/2009 12:38am

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.

Avatar
Martijn

Community Member, 271 Posts

5 December 2009 at 2:02am

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]')));

Avatar
roterl

Community Member, 44 Posts

5 December 2009 at 5:12am

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.

Avatar
roterl

Community Member, 44 Posts

5 December 2009 at 12:12pm

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.