753 Posts in 310 Topics by 289 members
| Go to End | Next > | |
| Author | Topic: | 4684 Views |
-
TreeDropdownField doesn't work with widget

28 January 2009 at 9:01am Last edited: 28 January 2009 9:04am
static $db = array(
'File' => 'Text'
);function getCMSFields(){
return new FieldSet(
new TreeDropdownField('File','Image file name','File'));
};i have the error: "Error getting data"
this solution doesn't work too
http://www.silverstripe.org/archive/show/118008 -
Re: TreeDropdownField doesn't work with widget

28 January 2009 at 9:16am
Yes, TreeDropdownFields don't work in widgets (yet).
Perhaps you can use a regular dropdownfield instead?
-
Re: TreeDropdownField doesn't work with widget

28 January 2009 at 9:34am
DropdownField works good but i have folder tree like this:+warsaw
- castle_image.jpg
- wisla_river.jpg+krakow
- castle_image.jpg
- mariacki_church_jpg
- wisla_river.jpgso i have to create two DropdownField to select full URL to the file
one for Folder
second for Image filei don't want to list all the image files in DropdownField, if i select Warsaw folder i want to list only this files which are in the Warsaw folder
is there any method to create it ?
-
Re: TreeDropdownField doesn't work with widget

28 January 2009 at 10:18am
The TreeDropdownField doesn't work with much. I created a SimpleTreeDropdownField, which is just a regular dropdown menu organized hierarchically. No javascript. Let me know if you want the code. You could use that to ajax-update your second dropdown menu for the files.
-
Re: TreeDropdownField doesn't work with widget

28 January 2009 at 10:57am
ok i have alternative version, maybe it is not very beautiful but i have something like a hierachy
new DropdownField('File_name','Select image:',DataObject::get("File")->toDropdownMap('Filename','Filename'))
-
Re: TreeDropdownField doesn't work with widget

28 January 2009 at 11:21am
Try this for the folder part:
<?php
class SimpleTreeDropdownField extends DropdownField
{
function __construct( $name, $title, $className = "Folder", $value = null, $form = null, $emptyString = null)
{
$this->className = $className;
$optionArray = $this->getHierarchy(0);
parent::__construct( $name, $title, $optionArray, $value, $form, $emptyString );
}
private function getHierarchy($parentID, $level = 0)
{
$options = array();
if($children = DataObject::get($this->className, "ParentID = $parentID")) {
foreach($children as $child) {
$indent="";
for($i=0;$i<$level;$i++) $indent .= " ";
$options[$child->ID] = $indent.$child->Title;
$options += $this->getHierarchy($child->ID, $level+1);
}
}
return $options;
}
}?>
-
Re: TreeDropdownField doesn't work with widget

28 January 2009 at 9:37pm
ok, where i should put this code ?
ImageWidget.php
class ImageWidget extends Widget {
[...]
return new FieldSet(
new DropdownField('File_name','Image file: ',$this->getHierarchy)
)[...]
}
class SimpleTreeDropdownField extends DropdownField {
}
doesn't workclass ImageWidget extends Widget {
[...]
return new FieldSet(
new DropdownField('File_name','Image file: ',$this->getHierarchy)
)[...]
}
class SimpleTreeDropdownField extends ImageWidget {
}
i get:
Fatal error: Declaration of SimpleTreeDropdownField::__construct() must be compatible with that of DataObjectInterface::__construct() in /home/wilgocki/domains/wilgocki.net/public_html/silverstripe/widgets_ImageWidget/ImageWidget.php on line 94
my previous code works but i need to wrap words after 50 chars (http://www.silverstripe.org/customising-the-cms/show/253177?showPost=253177)
new DropdownField('File_name','Select image:',DataObject::get("File")->toDropdownMap('Filename',wordwrap('Filename', 50, "\n", 1)))
| 4684 Views | ||
| Go to Top | Next > |


