webfox/silverstripe-dependentdropdownfield
Composer 安装命令:
composer require webfox/silverstripe-dependentdropdownfield
包简介
A silverstripe dropdown or listbox field that has it's options populated via ajax, based on the value of the field it depends on
README 文档
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);
统计信息
- 总下载量: 2.41k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2015-01-19