Ani*_*rya 5 validation kendo-ui kendo-grid kendo-dataviz
我正在使用API数据填充kendo - grid,但是在一个字段上添加验证也会自动为每个其他字段工作.
这是kendo-dataSource中的架构:
schema: {
model: {
id : "id",
fields: {
id: { editable: false, type: 'number'},
name: { editable: true, type : "string" },
unique_url: { editable: true , type: 'string'},
image_url : { editable: true, type : "string" },
title: {type : "string", validation: {
required: true,
validateTitle: function (input) {
console.log("I am inside validation",input.val());
if (input.val().length > 5) {
input.attr("data-validateTitle-msg", "Max length exceeded 5 characters only");
return false;
}
return true;
}
}
},
body: { editable: true, type : "string",validation: { max: 90, required: true, message : "Maximum characters should be 90"} },
adaccount_id: { editable: false, type: 'number'}
}
}
},
Run Code Online (Sandbox Code Playgroud)
在这里,我添加了标题字段的验证,但它也被称为其他字段.我正在添加一个验证快照---
请帮我找出错误.
您的代码中没有任何错误,但更像是Kendo Grid验证设计中的错误.即使您仅在title字段中指定验证功能,它也会针对您编辑的任何输入字段全局运行验证.
在validateTitle你需要筛选你想要的验证功能运行在其上输入.像这样的东西:
if (input.is("[name='title']") && input.val().length > 5) {
input.attr("data-validateTitle-msg", "Max length exceeded 5 characters only");
return false;
}
Run Code Online (Sandbox Code Playgroud)
如果您需要实时演示,您可以随时参考Telerik的在线演示,这些演示是可编辑的,非常便于玩弄东西.这是自定义验证的演示,他们同样必须过滤字段名称的输入.