Jump to:

2012 Posts in 1438 Topics by 621 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: 5557 Views
  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    No, getting no error. It just won't store the value.

    Never mind, looks like I don't need it anyway.

    But thanks

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    And TreeDrowndownField stores the value?

    The OptionalTreeDrowndownField extends the TreeDropdownField so I don't know why one would work and the other one doesn't. The only difference between the two I can think of is that if you do not select a value it tries to store a null value, but that should only be an issue if you don't select a value.

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    no, both of them didn't store the value.
    But when I use this code:

    new TreeDropdownField("InternLinkID", "Velg hvor artikkelen skal linkes til", "SiteTree"

    This stores the value.

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    Then it should also work for:

    new OptionalTreeDropdownField("InternLinkID", "Velg hvor artikkelen skal linkes til", "SiteTree"

  • frabraha
    Avatar
    Community Member
    49 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    yes, it should.
    But I don't need that function after all..

  • martimiz
    Avatar
    Forum Moderator
    1091 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    Been a long time since I posted this one Thanks, Marijn

  • silverseba
    Avatar
    Community Member
    26 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    I´m trying to get the OptionalTreeDropDownField working under SS 2.4, as the code above doesn´t return any sitetree when using it under SS 2.4.

    Obviuosly the method TreeDropdownField::gettree() has changed to TreeDropdownField::tree($request) in Version 2.4 (see doc: http://api.silverstripe.org/2.4/forms/fields-relational/TreeDropdownField.html#methodtree)

    My first try was to just change the method name to tree() (without any param). But this results in an 'missing argument' error and doesn´t return anything.

    So obviously you need to pass the parameter '$request' which is of the type 'SS_HTTPRequest'.

    My problem: I don´t know how to generate a variable with the current SS_HTTPRequest.
    Does anybody know how to correctly call the mehtod TreeDropdownField::tree($request), so that it returns the current Sitetree?

  • MarijnKampf
    Avatar
    Community Member
    164 Posts

    Re: TreeDropdownField: unselect selected value Link to this post

    Hi Silverseba,

    I had noticed that it didn't work, but didn't see the urgency of fixing it yet, your post encouraged me to though

    As the OptionalTreeDropdownField is an extension of TreeDropdownField we don't need to generate the SS_HTTPRequest $request variable. It is passed by the calling function to our function. Below the full updated code of the OptionalTreeDropdownField.

    <?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 = '</ul>';

       /**
        * Helper function to return the header (rather than defining same line twice).
        */
       function preTree() {
          return '<ul class="tree"><li id="" 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;
       }
    }

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