Jump to:

2011 Posts in 1436 Topics by 620 members

Form Questions

SilverStripe Forums » Form Questions » DependentDropdownField

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

Page: 1
Go to End
Author Topic: 590 Views
  • Drumstick
    Community Member
    20 Posts

    DependentDropdownField Link to this post


    Does someone understand how to use correct the DependentDropdownField?

    Like this it doesn't work...


    DependentDropdownField::create('ProductCategoryItem', 'ProductSubcategoryItem',

    Thanks for a tip.

  • Andre
    Community Member
    126 Posts

    Re: DependentDropdownField Link to this post

    Hi there, I have the same question.

    The Modules Description looks promising, but I have no Idea how to have two collections, where one is depending on the other (typical has_many relation) and map this to a dropdown and dependentdropdown field.

    Anyone here who got that ever to run?

    kind regards

  • innomedia
    Community Member
    1 Post

    Re: DependentDropdownField Link to this post

    Hi guys,

    i managed to get this thing working. All you need to do is:
    - set the Dependant field wirth ->setDepends()
    - load the values in the dependant field via callback

    Here is how it worked for me:
    $fields->addFieldToTab('Root.RelatedArticles', $blogModuleField = DropdownField::create('BlogModule', 'Blog Module', BlogHolder::get()->sort('Title', 'ASC')->map('ID', 'Title')));
    $fields->addFieldToTab('Root.RelatedArticles', $articleField = DependentDropdownField::create('LinkedArticleID', 'Related Blog Article', array('News', 'DropdownBlogArticles'))->setEmptyString('(No Article Selected)'));

    public static function DropdownBlogArticles($parent_ = null){
    return BlogEntry::get()->filter('ParentID', $parent_)->sort('Date', 'DESC')->limit(50)->map('ID', 'Title')->toArray();
    } else {
    return BlogEntry::get()->sort('Date', 'DESC')->limit(50)->map('ID', 'Title')->toArray();

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.