Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Form Questions

DependentDropdownField


Reply

3 Posts   623 Views

Avatar
Drumstick

28 July 2013 at 9:13am Community Member, 20 Posts

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.

Avatar
Andre

21 March 2014 at 11:47am Community Member, 126 Posts

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

Avatar
innomedia

17 April 2014 at 10:37pm Community Member, 1 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();
}
}