No, getting no error. It just won't store the value.
Never mind, looks like I don't need it anyway.
But thanks
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
No, getting no error. It just won't store the value.
Never mind, looks like I don't need it anyway.
But thanks
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.
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.
Then it should also work for:
new OptionalTreeDropdownField("InternLinkID", "Velg hvor artikkelen skal linkes til", "SiteTree"
yes, it should.
But I don't need that function after all.. :)
Been a long time since I posted this one :-) Thanks, Marijn
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?
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;
}
}