antonythorpe / silverstripe-knockout-forms
通过Knockout MVVM JavaScript库提供了增强的用户体验,以及与Silverstripe表单相关联的验证插件。Silverstripe生成表单,指定Knockout样式的表单字段,并通过Knockout js扩展将验证需求添加到可观察对象中。默认消息
4.0.0
2024-07-09 05:24 UTC
Requires
- silverstripe/framework: ^5.0.0
- silverstripe/vendor-plugin: ^2
Requires (Dev)
README
使用Knockout MVVM JavaScript库以及相关验证插件为Silverstripe表单提供增强的用户体验
为什么使用这个Silverstripe模块?
- 防止错误提交表单
- 实时验证响应
- 通过span元素或提示框显示消息
- 浏览器支持回ie6
工作原理
在Knockoutjs viewModel的可观察对象中添加验证需求。接下来,利用Knockout表单字段,使用Silverstripe创建表单。绑定后,字段值通过自定义绑定处理程序传递到可观察对象中。放置在可观察对象上的规则将控制字段验证。
本模块的方法
- 扩展Silverstripe表单字段,将Knockout可观察对象和值放置在元素上
- 使用Knockout-Validation验证字段
- 可选择禁用提交按钮,直到所有规则都满足
要求
文档
未来开发想法
- 添加更多字段
- 探索使用knockout-pre-render在网格中显示数据(将替换setKnockout绑定处理程序和重构模板/测试)。这个库目前只有一维。
欢迎提交拉取请求
建议的方法是扩展现有的Silverstripe字段。确保指定适当的绑定类型,并将来自trait类Common.php的getter转换为任何需要的方法。
namespace AntonyThorpe\Knockout; require_once('Common.php'); use SilverStripe\Forms\????Field; /** * Knockout NameOfNewField * * Creates a {@link NameOfNewField} with an additional data-bind attribute that links to a Knockout observable */ class KnockoutNameOfField extends ????Field { use \Knockout\Common; /** * bindingType */ protected $bindingType = "theKnockoutBindingHandler";
如果需要,向覆盖的字段类添加__construct函数。
修改框架表单模板以包含Knockout的绑定处理程序,并将其保存到templates/AntonyThorpe/Knockout。
测试
- 为新的表单字段创建模型测试
- 更新
KnockoutFormTest.php和KnockoutFormTestController.php以测试HTML中的绑定处理程序创建 - 将新的Knockout字段添加到KnockoutFormTestController类中的表单函数内
- 在KnockoutFormTest类中的testKnockoutForm函数中添加新的断言
- 添加到
docs/en/documentation.md
支持
抱歉,没有。