Jump to:

5514 Posts in 1733 Topics by 1219 members

Customising the CMS

SilverStripe Forums » Customising the CMS » TreeDropdownField doesn't save selection - SS2.4

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

Page: 1
Go to End
Author Topic: 1109 Views
  • Tama
    Avatar
    Community Member
    130 Posts

    TreeDropdownField doesn't save selection - SS2.4 Link to this post

    Howdy

    I have added the following code to create a selectable drop down tree of CMS pages for one of my page types:

    class ArchivePage extends Page {

       static $db = array(
             
       );

       static $has_one = array(
          'ArchivePageID' => 'SiteTree',
       );

       function getCMSFields(){
          $tree = new TreeDropdownField('ArchivePageID', 'Choose a Parent page to display an archive of the Child pages', 'SiteTree');
          $fields = parent::getCMSFields();
          $fields->addFieldToTab('Root.Content.Main', $tree, 'Content');
          
          return $fields;
       }

    }

    This displays a dropdown selection of all of the pages in the website but when I select a page and click "Save" the box resets to just reading "(Choose)".

    I'm sure I'm just making a simple mistake but I've been wading through the documentation and forums and haven't found anything that works.

    Hopefully someone can let me know what I'm missing.

    Cheers
    Tama

  • Tama
    Avatar
    Community Member
    130 Posts

    Re: TreeDropdownField doesn't save selection - SS2.4 Link to this post

    Update: I changed "ArchivePageID" to "ArchiveParent" to prevent any conflicts and it's still not working.

  • Tama
    Avatar
    Community Member
    130 Posts

    Re: TreeDropdownField doesn't save selection - SS2.4 Link to this post

    OK, sorted it out - thanks Mateusz.

    You have to remove ID from $has_one:

    static $has_one = array(
    'ArchivePage' => 'SiteTree',
    );

    But still include it in the getCMSFields:

    function getCMSFields(){
    $tree = new TreeDropdownField('ArchivePageID', 'Choose a Parent page to display an archive of the Child pages', 'SiteTree');
    $fields = parent::getCMSFields();
    $fields->addFieldToTab('Root.Content.Main', $tree, 'Content');

    return $fields;
    }

    1109 Views
Page: 1
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.