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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Form Questions /

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

DependentDropdownField


Go to End


3 Posts   1876 Views

Avatar
Drumstick

Community Member, 20 Posts

28 July 2013 at 9:13am

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

Community Member, 146 Posts

21 March 2014 at 11:47am

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

Community Member, 1 Post

17 April 2014 at 10:37pm

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();
}
}