webfox / silverstripe-dependentdropdownfield
This package is abandoned and no longer maintained.
No replacement package was suggested.
There is no license information available for the latest version (dev-master) of this package.
A silverstripe dropdown or listbox field that has it's options populated via ajax, based on the value of the field it depends on
dev-master
2015-01-15 02:52 UTC
Requires
- php: >=5.3.2
- silverstripe/cms: 3.*
- silverstripe/framework: 3.*
This package is auto-updated.
Last update: 2022-10-14 02:51:52 UTC
README
A silverstripe dropdown or listbox field that has it's options populated via ajax, based on the value of the field it depends on
Based on the module by sheadawson
Requirements
SilverStripe 3
Usage example
DropdownField
$postsSource = function ($val) {
/** @var Category $category */
$category = Category::get_by_id('Category', $val);
return $category->Posts()->map()->toArray();
};
$currentPost = $this->PostID;
/** @var DependentDropdownField $postField */
$postField = DependentDropdownField::create('AssignedPost', 'Select Featured Post', $postsSource);
$postField->setMultiple(true);
$postField->setDefaultItems($currentPost);
$postField->setDepends($fields->fieldByName('Root.Main.CategoryID'));
$fields->addFieldToTab('Root.Main', $postsField);
ListboxField
$postsSource = function ($val) {
/** @var Category $category */
$category = Category::get_by_id('Category', $val);
return $category->Posts()->map()->toArray();
};
$currentPosts = $this->Posts()->column('ID');
/** @var DependentListboxField $postsField */
$postsField = DependentListboxField::create('AssignedPosts', 'Select Posts', $postsSource);
$postsField->setMultiple(true);
$postsField->setDefaultItems($currentPosts);
$postsField->setDepends($fields->fieldByName('Root.Main.CategoryID'));
$fields->addFieldToTab('Root.Main', $postsField);