sheadawson/silverstripe-select2

此软件包最新版本(1.0.1)没有提供许可信息。

基于 http://ivaynberg.github.com/select2/ 的 SilverStripe 表单字段集

安装量: 22,723

依赖关系: 6

建议者: 0

安全: 0

星标: 18

关注者: 7

分支: 19

开放问题: 8

类型:silverstripe-vendormodule

1.0.1 2016-01-25 20:58 UTC

This package is auto-updated.

Last update: 2024-08-25 08:06:43 UTC


README

基于 http://ivaynberg.github.com/select2/ 的四个 SilverStripe 表单字段。

要求

SilverStripe 框架 ^4

维护者联系方式

Select2Field

一个基本的下拉字段,带有增强的 Select2 UI

MultiSelect2Field

一个多选下拉字段,带有 Select2 UI

GroupedDropdownField

扩展 SilverStripes GroupedDropdownField 以添加 Select2 UI

AjaxSelect2Field

AjaxSelect2Field 是一个下拉字段,利用 select2 的 ajax 结果加载和无限滚动功能。当您需要从成百上千条记录中选择对象时,这非常有用,否则标准下拉/选择字段可能会变得缓慢且加载沉重。请注意,当前此功能不支持多选。欢迎 PR ;)

用法

基本实现将使用配置默认值,提供一个 SiteTree 对象的下拉列表,适合搜索和选择页面。

$field = AjaxSelect2Field::create('PageID');

配置

您可以使用以下 API 配置 AjaxSelect2Field 实例。setConfig() 方法也是可链式的。

示例

// Set a class to search for. Defaults to SiteTree
$field->setConfig('classToSearch', 'MyCustomObject');

// Set a list of fields to search on. Default is Title 
$field->setConfig('searchFields', array('Title', 'ID'));

// Limit the number of results loaded per page (scroll set). Default is 200
$field->setConfig('resultsLimit', 100);

// The number of characters typed before search results are displayed. Default is 2.
$field->setConfig('minimumInputLength', 3);

// Configure how items should be displayed in the results list. The value gets parsed by the template parser
// You can use HTML too. Default is '$Title'.
$field->setConfig('resultsFormat', '<strong>$Title</strong><br />$AbsuluteLink');

// Configure how the currently selected item should be displayed. Default is '$Title'.
$field->setConfig('selectionFormat', '$Title ($ClassName)');

// Configure the text displayed when no item is selected. Default is 'Search...'
$field->setConfig('placeholder', 'Search for a Page...');

// Allow selection of multiple results. NOTE - you must handle the selected IDs (comma separated list) in code
$field->setConfig('multiple', true);