Kendo-Grid 列字段验证 [英] Kendo-Grid column field validation

查看:11
本文介绍了Kendo-Grid 列字段验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 API 数据填充剑道网格,但在一个字段上添加验证也自动适用于所有其他字段.

I am working on populating kendo--grid with APIs data but on adding validation on one field is automatically working for every other fields too.

这是 kendo-dataSource 中的架构:

Here is schema inside 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'}
                       }
                   }
                },  

在这里,我为标题字段添加了验证,但它也被其他字段调用.我正在添加一个验证快照---

Here I have added validation for title field but its getting called for others fields too. I am adding one snapshot of validation---

请帮我找出其中的错误.

Please help me to find errors in it.

推荐答案

您的代码实际上没有任何错误,而更像是 Kendo Grid 验证设计中的错误.即使您仅在 title 字段中指定验证函数,它也会对您编辑的任何输入字段全局运行验证.

There isn't really any error in your code, but more like an error in Kendo Grid's validation design. Even though you specify the validation function only in the title field, it will run the validation globally for any input field that you edit.

validateTitle 中,您需要过滤要运行验证函数的输入.像这样:

In validateTitle you need to filter which input you want the validating function to run on. Something like this:

if (input.is("[name='title']") && input.val().length > 5) {
    input.attr("data-validateTitle-msg", "Max length exceeded 5 characters only");
    return false;
}

如果您需要实时运行的演示,您可以随时参考 Telerik 的在线演示,这些演示可编辑,非常方便玩弄东西.这是用于自定义验证的演示他们同样必须过滤字段名称的输入.

If you need a live working demo, you can always refer to Telerik's online demos that are editable, very handy for playing around with things. Here's the demo for custom validation where they similarly have to filter the input for the field name.

这篇关于Kendo-Grid 列字段验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆