剑道电网自定义的验证规则不工作(Kendo Grid Custom Validation Rules

2019-10-30 10:41发布

我试图使用自定义的验证规则与剑道的Web UI数据网格,但我一直没能得到它的工作。 我能够自定义规则附加到网格,当用户离开网格单元它被调用。 该规则函数也返回false指示输入无效。 但是,从细胞中删除的名称,然后按Tab键出来后不显示错误消息。 我在想什么?

的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"
    }
};

Answer 1:

您的数据源设置创建自定义的验证规则,

我曾尝试在你的jsfiddle和工作正常。

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 Grid Custom Validation Rules Not Working