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

TreeDropdownField: unselect selected value

Go to End

21 Posts   9654 Views


Community Member, 26 Posts

18 June 2010 at 3:08am

Thank you Marijn for your fast response! Works like a charm!
And a very smooth backward compatibility for SS 2.3 as well.


Community Member, 5 Posts

8 March 2011 at 7:40am

I just adjusted your code a little bit for the 2.4.4 version. Now it is possible trigger all childknodes.

Hope it works for you.

* TreeDropdown-like field that gives you a tree of items including an empty field, using ajax.
* Author: Marijn Kampf
* Date:             24 Nov 2009
* Version:          2.0
* Revision date:      17 June 2010
* Changes:          Updated to work with SilverStripe 2.4, tree function added.
class OptionalTreeDropdownField extends TreeDropdownField {
   private static $postTree = '</li></ul>';

    * Helper function to return the header (rather than defining same line twice).
   function preTree() {
      return '<li id="0" class="l"> <a>' . _t('OptionalTreeDropdownField.NONE', "(None)", PR_MEDIUM, 'Non selected value of a dropdown') . '</a>';

    * Return the site tree
    * For version 2.3 and earlier
   /*function gettree() {
      echo $this->preTree();
      echo $this->postTree;

    * Get the whole tree of a part of the tree via an AJAX request with empty / none item prepended.
    * @param SS_HTTPRequest $request
    * @return string
    * for version 2.4 and later
   function tree($request) {
      return $this->preTree() . parent::tree($request) . $this->postTree;


Community Member, 3 Posts

9 November 2011 at 11:04am

Hi guys.

That was exactly what I was looking for! Thank you so much!
But there is a little bug in SS 2.4.5.
Everything is working as expected, as long as you select pages within the root level. If you open a subtree and try to select pages within it the pages are not selectable (Even the yellow hover highlighting is not working).

Any suggestions?


Community Member, 33 Posts

5 March 2012 at 11:35am


use DOM's SimpleTreeDropdownField:

	$f = new SimpleTreeDropdownField("PageLinkToID","Page link to", "SiteTree");




Community Member, 21 Posts

30 July 2012 at 12:36pm

Thanks Pali - Very nice simple solution! :)

Go to Top