1794 Posts in 590 Topics by 562 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 973 Views |
-
Use TreeMultiselectField in frontend form

15 July 2010 at 9:21am
Hey, I want to use a TreeMultiselectField like this
in the frontend.
But I want to set the selectable objects with a query, like $objects = DataObject::get('Group', ...);
There is no relation between the objects in the dropdown and the page.
How can I implement it?
Perhaps something like this?$dropdown = new TreeDropdownField(...);
$dropdown->setObjects($objects); -
Re: Use TreeMultiselectField in frontend form

15 July 2010 at 11:23am
You can only use TreeMultiSelectField with dataobjects that implement Hierarchy (eg SiteTree and Groups). You can't set object sets AFAIK but you can set a class name and the root node ID (level as to start at). Also some filter function which may provide something but I haven't used it myself.
http://api.silverstripe.org/2.4/forms/fields-relational/TreeDropdownField.html
-
Re: Use TreeMultiselectField in frontend form

15 July 2010 at 5:49pm Last edited: 16 July 2010 6:13pm
thx for your reply!
ok in this case I want to display some group DataObjects (which -> depends on the current user), but does the page must have a relation like has_many?
The problem is, that another class have this relation, but the form should be displayed somewhere else.
I think it is easier to create a new "FlexTreeMultiselectField" by my own to handle that... -
Re: Use TreeMultiselectField in frontend form

16 July 2010 at 6:14pm
OK here is a solution by using the TreeMultiselectField:
The easiest way is to check the ajax request, which gets a 404 error
I used this to to add a function to handle the request, its name is always the Form ID like "ContactForm" on the current page.
It needs a valid HTML with a <ul>, see below:function ContactForm() {
$objects = ... // Perhaps a db query
$HTMLStr = '<ul class="tree">';
foreach ($objects as $object) {
$HTMLStr .= '<li id="selector-ViewerGroups-'.$object->ID.'" class="Group closed"><a>'.$object->Title.'</a></li>';
}
$HTMLStr .= '</ul>';
echo $HTMLStr;
exit;
}
By default its styled by cms.
| 973 Views | ||
|
Page:
1
|
Go to Top |


