Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » TreeDropdownField: unselect selected value

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

Page: 1 2 3
Go to End
Author Topic: 5521 Views
  • silverseba
    Avatar
    Community Member
    26 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

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

  • flozwo
    Avatar
    Community Member
    5 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    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.

    <?php
    /**
    * TreeDropdown-like field that gives you a tree of items including an empty field, using ajax.
    * Author: Marijn Kampf www.exadium.com
    * 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();
    parent::gettree();
    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;
    }
    }
    ?>

  • mayko
    Avatar
    Community Member
    3 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    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?

  • pali
    Avatar
    Community Member
    33 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    hi,

    use DOM's SimpleTreeDropdownField:

       $f = new SimpleTreeDropdownField("PageLinkToID","Page link to", "SiteTree");
       $f->setHasEmptyDefault(true);

    regards

    pali

  • RuthAdele
    Avatar
    Community Member
    19 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    Thanks Pali - Very nice simple solution!

    5521 Views
Page: 1 2 3
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.