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're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

TreeDropdownField: unselect selected value


Go to End


21 Posts   8252 Views

Avatar
frabraha

Community Member, 49 Posts

10 March 2010 at 10:44pm

Edited: 10/03/2010 10:57pm

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

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

But thanks

Avatar
MarijnKampf

Community Member, 176 Posts

10 March 2010 at 11:09pm

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.

Avatar
frabraha

Community Member, 49 Posts

10 March 2010 at 11:48pm

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.

Avatar
MarijnKampf

Community Member, 176 Posts

11 March 2010 at 12:00am

Then it should also work for:

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

Avatar
frabraha

Community Member, 49 Posts

11 March 2010 at 12:31am

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

Avatar
martimiz

Forum Moderator, 1391 Posts

11 March 2010 at 5:48am

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

Avatar
silverseba

Community Member, 26 Posts

17 June 2010 at 11:19pm

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?

Avatar
MarijnKampf

Community Member, 176 Posts

18 June 2010 at 2:59am

Edited: 18/06/2010 3:00am

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