Jump to:

794 Posts in 408 Topics by 304 members

Widgets

SilverStripe Forums » Widgets » TreeDropdownField doesn't work with widget

Discuss SilverStripe Widgets.

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

Page: 1 2
Go to End
Author Topic: 5678 Views
  • snaip
    Avatar
    Community Member
    180 Posts

    TreeDropdownField doesn't work with widget Link to this post

    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

  • dio5
    Avatar
    Community Member
    501 Posts

    Re: TreeDropdownField doesn't work with widget Link to this post

    Yes, TreeDropdownFields don't work in widgets (yet).

    Perhaps you can use a regular dropdownfield instead?

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: TreeDropdownField doesn't work with widget Link to this post


    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.jpg

    so i have to create two DropdownField to select full URL to the file
    one for Folder
    second for Image file

    i 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 ?

  • UncleCheese
    Avatar
    4085 Posts

    Re: TreeDropdownField doesn't work with widget Link to this post

    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.

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: TreeDropdownField doesn't work with widget Link to this post

    UncleCheese yes please

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: TreeDropdownField doesn't work with widget Link to this post

    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'))

  • UncleCheese
    Avatar
    4085 Posts

    Re: TreeDropdownField doesn't work with widget Link to this post

    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 .= "&nbsp;&nbsp;";
                $options[$child->ID] = $indent.$child->Title;
                $options += $this->getHierarchy($child->ID, $level+1);
             }
          }
          return $options;
       }
    }

    ?>

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: TreeDropdownField doesn't work with widget Link to this post

    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 work

    class 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)))

    5678 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.