validation - How does kendo form validation custom required work?
问题描述
I would like to add a required field to a Kendo form. This works with:
validation: { required: true },
If I now want to set required myself in a function, this no longer works.
validation: {
required: function(){
return true;
}
},
I have created an example: https://dojo.telerik.com/epEzewIt/5
If no entry is made in the "MultiSelect" field, the required variant as a function is no longer displayed: "MultiSelect is required" when it is empty.
How can I store required with a function?
解决方案
If you want to execute some code one time you can use an anonymous function like:
validation: {
required: (function(){
return true; // run your rules here
})()
But, as documentation suggests, those (required, max/min, pattern, etc.) are field attributes that map to HTML rules. So you can't pass a function.
Why not use the kendoValidator on your submit action. This can be used to validate all the fields and set custom messages.
Here are more details on how to use Kendo Validator to create custom validations: https://docs.telerik.com/kendo-ui/controls/editors/validator/rules
There are a lot of examples there.
推荐阅读
- google-apps-script - 请再看一遍:Google 高级幻灯片 API 在现有表格中插入文本
- selenium - 无法单击按钮:预期条件失败:等待元素可单击:代理元素:DefaultElementLocator 'By.xpath: //*[')]'
- javascript - EJS 接收包含代码为字符串的 json
- android - 在 webview 中发布请求下载,但如何下载文件?
- google-cloud-platform - GCP TPU ssh 问题
- rust - 如何在不丢弃对象的情况下解构对象?
- android - 用于接收 iOS 和 Android 消息的 Cordova 插件
- java - 将一个用户的图像上传到 Firebase 存储时,数据库中每个用户的图像链接都会更新
- css - CSS 网格布局 - 如果一个项目居中,如果两个让它们占据均匀空间
- sql-server - 从 S3 存储桶恢复 AWS RDS SQL Server 上的备份文件时,生命周期停留在已创建状态