Kendo网格自定义验证规则不起作用 [英] Kendo Grid Custom Validation Rules Not Working

查看:101
本文介绍了Kendo网格自定义验证规则不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将自定义验证规则与Kendo Web UI数据网格一起使用,但无法使其正常运行.我可以将自定义规则附加到网格,并且当用户离开网格单元时它会被调用.规则函数还返回false,以指示输入无效.但是,从单元格中删除名称,然后跳出后,不会显示错误消息.我想念什么?

I’m trying to use custom validation rules with a Kendo Web UI data grid but I haven’t been able to get it working. I’m able to attach a custom rule to the grid and it does get called when the user leaves the grid cell. The rule function also returns false to indicate that the input is not valid. But the error message is not displayed after deleting the name from a cell and then tabbing out. What am I missing?

JSFiddle: http://jsfiddle.net/davidsalahi/qMRBc/

JSFiddle: http://jsfiddle.net/davidsalahi/qMRBc/

var validatorRules = {
    rules: {
        // This rule is executed when leaving a cell but the return value of false doesn't display any error message or prevent leaving the cell 
        customRule1: function (input) {
            // OpCode must not be empty
            if (input.attr("name") == "ProductName") {
                return $.trim(input.val()) !== "";
            }
        }
    },
    messages: {
        customRule1: "All fields are required"
    }
};

推荐答案

在数据源设置上创建自定义验证规则,

Create custom validation rule on your data source setting,

我已经尝试过您的jsfiddle并正常工作.

I have tried on your jsfiddle and worked correctly.

http://jsfiddle.net/pehlizm/qMRBc/4/

    var crudServiceBaseUrl = "http://demos.telerik.com/kendo-ui/service",
    dataSource = new kendo.data.DataSource({
        transport: {
            read: {
                url: crudServiceBaseUrl + "/Products",
                dataType: "jsonp"
            },
            parameterMap: function (options, operation) {
                if (operation !== "read" && options.models) {
                    return {
                        models: kendo.stringify(options.models)
                    };
                }
            }
        },
        batch: true,
        pageSize: 20,
        schema: {
            model: {
                id: "ProductID",
                fields: {
                    ProductID: {
                        editable: false,
                        nullable: true
                    },
                   ProductName: {                   //changes starts here
                       type: "string",
                       validation: {
                                   custom: function(input) {
                                         // set the custom message
                                         input.attr("data-custom-msg", "Error");

                                          if (input.attr("name") == "ProductName") {
                                             return  $.trim(input.val()) !== "";
                                  }
                                  }
                              }
                         },                           //ends here
                    UnitPrice: {
                        type: "number",
                        validation: {
                            required: true,
                            min: 1
                        }
                    }
                }
            }
        }
    });

这篇关于Kendo网格自定义验证规则不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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