evosoftcz / form-selectize
Nette 框架表单扩展
3.1.0
2024-01-09 08:29 UTC
Requires
- php: >= 8.1
- nette/di: >= 3.0.0
- nette/forms: >= 3.0.0
- nette/php-generator: >= 3.0.0
- nette/utils: >= 3.0.0
README
Nette 框架表单扩展
更多文档
- [javascript 设置] (https://github.com/Olicek/form-selectize/blob/master/docs/en/javascript.md)
- [ajax] (https://github.com/Olicek/form-selectize/blob/master/docs/en/ajax.md)
要求
- Nette 3.0
- PHP 7.2+
- jQuery 1.8+
- Selectize.js - 包含更多功能
安装
安装 evosoftcz/form-selectize 的最佳方式是使用 Composer
"repositories": [ { "url": "https://github.com/evosoftcz/form-selectize.git", "type": "git" } ], "require": { "evosoftcz/form-selectize": "^2.0" },
在安装服务器端之后,您还需要安装客户端。
从客户端链接 selectize.init.js
并调用 selectize()
函数。
最后一步是在您的 neon 配置中启用扩展
extensions:
selectize: Selectize\Form\Control\SelectizeExtension
默认配置
selectize:
mode: full # second mode is `select` for selection just 1 option
create: on
maxItems: null
delimiter: #/
plugins:
- remove_button
valueField: id
labelField: name
searchField: name
全模式下的数组数据
array (2)
0 => array (2)
id => 1
name => "First item"
1 => array (2)
id => 2
name => "Second item"
id 被设置为 valueField,name 作为 labelField 和 searchField 在 config.neon 中设置。您可以使用任何内容,只需在 config.neon 或 addSelectize 方法中设置即可。例如
valueField: slug
选择模式下的数组数据
选择模式下的数据与 SelectBox 相同
array (2)
1 => "First item",
2 => "Second item"
使用
来自 config.neon 的默认设置
$form->addSelectize('tags', 'štítky', $arrayData);
方法第一种方式(数组)中的自定义设置
$form->addSelectize('tags', 'štítky', $arrayData, ['create' => false, 'maxItems' => 3]);
方法第一种方式(方法)中的自定义设置
$form->addSelectize('tags', 'štítky', $arrayData)->setValueField('slug')->delimiter('_');
输出是
选择模式
dump($form->values->tags); // return "1"
全模式
在全模式下,它将返回包含 valueField 值的数组。如果您创建了新的标签,它将位于子数组中,其中包含纯文本。
array (3)
0 => "1"
1 => "2"
new => array (1)
0 => "Third item"
禁用项
在全模式下,它支持在 droplist 中禁用项
array (2)
0 => array (3)
'id' => 1
'name' => "foo"
'enabled' => true
1 => array (3)
'id' => 2
'name' => "bar"
'enabled' => false