vunamhung / cmb2_select2
这是一个CMB2扩展仓库,它帮助修改CMB2的默认行为并扩展其功能。
1.0.2
2020-02-26 03:20 UTC
Requires
- php: >=5.6.0
This package is auto-updated.
Last update: 2024-09-12 06:04:06 UTC
README
描述
此插件基于Select2提供两种额外的字段类型
select2
字段与默认的select
字段类似。然而,它添加了类似自动补全的搜索,允许您快速从长列表中进行选择multiselect2
字段允许您使用类似自动补全的搜索选择多个值。值可以被拖放以重新排序
用法
select2
- 带有自动补全搜索的选项框。示例
$cmb->add_field( array( 'name' => 'Cooking time', 'id' => $prefix . 'cooking_time', 'desc' => 'Cooking time', 'type' => 'select2', 'options' => array( '5' => '5 minutes', '10' => '10 minutes', '30' => 'Half an hour', '60' => '1 hour', ), ) );
multiselect2
- 可拖放重新排序的多值选项框。示例
$cmb->add_field( array( 'name' => 'Ingredients', 'id' => $prefix . 'ingredients', 'desc' => 'Select ingredients. Drag to reorder.', 'type' => 'multiselect2', 'options' => array( 'flour' => 'Flour', 'salt' => 'Salt', 'eggs' => 'Eggs', 'milk' => 'Milk', 'butter' => 'Butter', ), ) );
占位符
您可以通过属性数组指定占位符文本。示例
$cmb->add_field( array( 'name' => 'Ingredients', 'id' => $prefix . 'ingredients', 'desc' => 'Select this recipes ingredients.', 'type' => 'multiselect2', 'options' => array( 'flour' => 'Flour', 'salt' => 'Salt', 'eggs' => 'Eggs', 'milk' => 'Milk', 'butter' => 'Butter', ), 'attributes' => array( 'placeholder' => 'Select ingredients. Drag to reorder' ), ) );
自定义Select2配置和覆盖默认配置选项
您可以使用HTML5 data-*
属性定义Select2配置选项。建议阅读Select2网站上关于可用选项的说明。示例
$cmb->add_field( array( 'name' => 'Ingredients', 'id' => $prefix . 'ingredients', 'desc' => 'Select ingredients. Drag to reorder.', 'type' => 'multiselect2', 'options' => array( 'flour' => 'Flour', 'salt' => 'Salt', 'eggs' => 'Eggs', 'milk' => 'Milk', 'butter' => 'Butter', ), 'attributes' => array( 'data-maximum-selection-length' => '2', ), ) );