Jump to:

22979 Posts in 11815 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » TreeDropdownField: default value

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1 2
Go to End
Author Topic: 3154 Views
  • dacar
    Avatar
    Community Member
    168 Posts

    TreeDropdownField: default value Link to this post

    Hi,

    does anybody know, how to get the saved value from a TrreDropdownField. How can you use "objectForKey"?
    Can anybody give an example?

    new TreeDropdownField('BannerLinkInternID', 'Bitte eine interne Verlinkung wählen', 'SiteTree', 'ID', 'Title', true);

    Greetings, Carsten.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: TreeDropdownField: default value Link to this post

    does anybody know, how to get the saved value from a TrreDropdownField. How can you use "objectForKey"?
    Can anybody give an example?

    Not exactly sure what you mean by objectForKey but what I think your getting at is how you get the BannerLinkIntern object. Well with a TreedropdownField you should have setup a has_one relation on that page of 'BannerLinkIntern' => 'SiteTree' so to access the object in templates you can use $BannerLinkIntern to access the related page or in the PHP $this->BannerLinkIntern() to get the object.

  • dacar
    Avatar
    Community Member
    168 Posts

    Re: TreeDropdownField: default value Link to this post

    Hi Willr,

    thats all clear and works fine. But if i choose "home" from the list (for e.g.) and save the date to the db, then the page (backend) is reloaded and the value of the list is: "(Choose or type search)".

    What do i have to do to show "Home" as the selected value after saving the data to DB?

    objectforkey: [url=http://api.silverstripe.com/2.4/forms/fields-relational/TreeDropdownField.html#methodobjectForKey][url]http://api.silverstripe.com/2.4/forms/fields-relational/TreeDropdownField.html#methodobjectForKey

    Thanks for your reply, Carsten.

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: TreeDropdownField: default value Link to this post

    Sounds like the 'home' value isn't saving. Have you got a has_one relationship setup correctly between this page and sitetree and ran a /dev/build. You should after building a correct has_one relationship a column in your database 'BannerLinkInternID' if you don't have this column then the treedropdownfield cannot save its value.

  • jebbench
    Avatar
    Community Member
    7 Posts

    Re: TreeDropdownField: default value Link to this post

    I'm having the same problem, the field isn't saving back to the database. I can't get the link from my template and the field shows Choose a page rather than the page I selected.

    The code I'm using is:

    class Module extends Page {
    static $db = array(
    );
    static $has_one = array(
    'Photo' => 'Image',
    'Header' => 'Image',
    'LinkedPage' => 'SiteTree'
    );
    static $defaults = array(
    "ShowInMenus" => 0,
    );
    static $can_be_root = false;
    static $default_parent = 'HomePage';

    function getCMSFields() {
    $fields = parent::getCMSFields();
    $fields->addFieldToTab("Root.Content.Main", new ImageField('Header'));
    $fields->addFieldToTab("Root.Content.Main", new ImageField('Photo'));
    $fields->addFieldToTab('Root.Content.Main', new TreeDropdownField('LinkedPage', 'Page to link to', 'SiteTree'));
    $fields->removeFieldFromTab('Root.Content.Main', 'MenuTitle');
    $fields->removeByName('Metadata');
    return $fields;
    }

    }

    and in the template

    $LinkedPage.Link

    Am I doing something wrong or is this a bug?

    Cheers,

    James Bench

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: TreeDropdownField: default value Link to this post

    You need to use LinkedPageID instead of LinkedPage in your treedropdownfield constructor.

  • jebbench
    Avatar
    Community Member
    7 Posts

    Re: TreeDropdownField: default value Link to this post

    Cheers, that's fixed it

  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: TreeDropdownField: default value Link to this post

    I'm a clouts, again I don't know what I'm doing wrong.
    Same as above not getting id saved into the has_oneID field in the database.

       static $has_one = array(
          "LinkTo" => "SiteTree"
       );

    in getCMSFields_forPopup I'm adding and to and returning

    $fields->addFieldToTab( 'Root.Main', new TreeDropdownField("LinkToID", "Link To This Page","SiteTree"));

    I'm also trying SimpleTreeDropdownField as well, neither work.
    Doing a little homepage captions dataobject, there's only about 3, easier enough to swap out manually. But I like using Silver Stripe to the EXTREME!
    p.s. using SS 2.4

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