sheadawson/silverstripe-dependentdropdownfield

一个基于Ajax填充选项的SilverStripe下拉字段,这些选项根据它所依赖的字段的值来设置

安装次数: 185,538

依赖项: 14

建议者: 0

安全性: 0

星标: 28

关注者: 8

分支: 36

开放问题: 9

类型:silverstripe-vendormodule

3.0.0 2023-02-22 18:12 UTC

This package is auto-updated.

Last update: 2024-09-23 01:13:24 UTC


README

一个通过Ajax填充选项的SilverStripe下拉字段,这些选项基于它所依赖的字段的值。

需求

SilverStripe 4 或 5

安装

composer require sheadawson/silverstripe-dependentdropdownfield

使用示例

// 1. Create a callable function that returns an array of options for the DependentDropdownField.
// When the value of the field it depends on changes, this function is called passing the
// updated value as the first parameter ($val)
$datesSource = function($val) {
	if ($val == 'one') {
		// return appropriate options array if the value is one.
	}
	if ($val == 'two') {
		// return appropriate options array if the value is two.
	}
};

$fields = FieldList::create(
	// 2. Add your first field to your field list,
	$fieldOne = DropdownField::create('FieldOne', 'Field One', ['one' => 'One', 'two' => 'Two']),
	// 3. Add your DependentDropdownField, setting the source as the callable function
	// you created and setting the field it depends on to the appropriate field
	DependentDropdownField::create('FieldTwo', 'Field Two', $datesSource)->setDepends($fieldOne)
);