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: 5695 Views
  • UncleCheese
    Avatar
    4085 Posts

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

    Why do you have it extending ImageWidget? It's a subclass of DropdownField. Use the code as I gave it to you, and add the class anywhere in your ImageWidget.php file.

    Then you can add new SimpleTreeDropdownField to your fieldset.

  • danqxx
    Avatar
    Community Member
    14 Posts

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

    UncleCheese, thanks very much for the workaround class. I especially like the way you can just change the name from TreeDropdownField to SimpleTreeDropdownField in the fieldset and it works.

  • Garrett
    Avatar
    Community Member
    245 Posts

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

    I too am using SimpleTreeDropdownField in getCMSFields_forPopup() and it works fine (thanks as always @UC). Question, though, in my DataObjectManager, I'd like to get the Title of the selected page in the SiteTree to display instead of the ID. In my DataObject, I've got:

    public static $has_one = array(
    "LinkedPage" => "SiteTree"
    );
    .....
    public static $field_names = array(
    "Title" => "Title",
    "PageName" => "Link to Page",
    "Content" => "Content"
    );
    .....
    public function PageName() {
    $Page = DataObject::get_by_id("SiteTree", $this->LinkedPageID);
    return $Page->Title;
    }

    But obviously I'm getting an "Unknown column 'PageName' in 'field list'" when I click on the page in the CMS. Any idea how I can accomplish what I want here?

    Thanks again,
    Garrett

  • nicmart
    Avatar
    Community Member
    1 Post

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

    I've found where is the problem in using the TreeDropDownField in Widgets (in SS 2.4.7), and I have a simple workaround for that.

    The problem is that the method Form::handleField() is not able to find and return the field to the ajax call that is thrown when you click on the dropdown.

    Since, in cms/javascript/WidgetAreaEditor.js the name of dropdown fields that are in widgets are overwritten with the string "Widget_TDF_Endpoint", it suffices then to modify the sapphire/forms/Form.php and add this few lines to the handleField method (those between START_MOD and END_MOD):

       function handleField($request) {
          $field = $this->dataFieldByName($request->param('FieldName'));
          
          if($field) {
             return $field;
          } else {
             //START_MOD: TreeDropdownField in Widgets
             $fieldName = $request->param('FieldName');
             if ($fieldName == 'Widget_TDF_Endpoint') {
                return new TreeDropdownField($fieldName, null, 'SiteTree');
             }
             //END_MOD
             // falling back to fieldByName, e.g. for getting tabs
             return $this->Fields()->fieldByName($request->param('FieldName'));
          }
       }

    I hope this helps.

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