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.

Customising the CMS /

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

TreeDropdownField doesn't save selection - SS2.4


Go to End


3 Posts   1686 Views

Avatar
Tama

Community Member, 138 Posts

13 July 2010 at 1:14pm

Howdy

I have added the following code to create a selectable drop down tree of CMS pages for one of my page types:

class ArchivePage extends Page {

	static $db = array(
			
	);

	static $has_one = array(
		'ArchivePageID' => 'SiteTree',
	);

	function getCMSFields(){
		$tree = new TreeDropdownField('ArchivePageID', 'Choose a Parent page to display an archive of the Child pages', 'SiteTree');
		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Content.Main', $tree, 'Content');
		
		return $fields;
	}

}

This displays a dropdown selection of all of the pages in the website but when I select a page and click "Save" the box resets to just reading "(Choose)".

I'm sure I'm just making a simple mistake but I've been wading through the documentation and forums and haven't found anything that works.

Hopefully someone can let me know what I'm missing.

Cheers
Tama

Avatar
Tama

Community Member, 138 Posts

13 July 2010 at 2:10pm

Update: I changed "ArchivePageID" to "ArchiveParent" to prevent any conflicts and it's still not working.

Avatar
Tama

Community Member, 138 Posts

14 July 2010 at 9:07am

OK, sorted it out - thanks Mateusz.

You have to remove ID from $has_one:

   static $has_one = array( 
      'ArchivePage' => 'SiteTree', 
   );

But still include it in the getCMSFields:

   function getCMSFields(){ 
      $tree = new TreeDropdownField('ArchivePageID', 'Choose a Parent page to display an archive of the Child pages', 'SiteTree'); 
      $fields = parent::getCMSFields(); 
      $fields->addFieldToTab('Root.Content.Main', $tree, 'Content'); 
       
      return $fields; 
   }