Jump to:

1976 Posts in 1306 Topics by 607 members

Form Questions

SilverStripe Forums » Form Questions » DependentDropdownField

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

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

    DependentDropdownField Link to this post

    Hi

    Does someone understand how to use correct the DependentDropdownField?

    Like this it doesn't work...

    DropdownField::create('ProductCategoryItem','ProductCategoryItem',$map1),

    DependentDropdownField::create('ProductCategoryItem', 'ProductSubcategoryItem',
    $map1,
    $map2[1]
    ),

    Thanks for a tip.

  • Andre
    Avatar
    Community Member
    125 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
    Avatar
    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:
    getCMSFields(){
    $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)'));
    $articleField->setDepends($blogModuleField);
    }

    public static function DropdownBlogArticles($parent_ = null){
    if($parent_){
    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();
    }
    }

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