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

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

问题描述

我正在用API数据填充kendo--grid,但是在一个字段上添加验证也会自动对其他每个字段起作用.

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天全站免登陆