Thank you Marijn for your fast response! Works like a charm!
And a very smooth backward compatibility for SS 2.3 as well.
We've moved the forum!
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.
- Previous 10 entries
- 1
- 2
- Page 33(current)
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;
}
}
?>
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?
hi,
use DOM's SimpleTreeDropdownField:
$f = new SimpleTreeDropdownField("PageLinkToID","Page link to", "SiteTree");
$f->setHasEmptyDefault(true);
regards
pali
Thanks Pali - Very nice simple solution! :)
- Previous 10 entries
- 1
- 2
- Page 33(current)