2

我正在使用剑道网格,并希望通过同一记录中的另一个字段验证一个字段的最小值。

意思是我的数据是这样的:-

var courses = [{
    CourseID : 1,
    CourseName : "iPhone",
    MinAge: 12,
    MaxAge : 22,
    MinAgeThreshold : 10,
    MaxAgeThreshold : 30,
    StartDate: "12/10/2014",
},
{
    CourseID : 2,
    CourseName : "Android",
    MinAge: 12,
    MaxAge : 22,
    MinAgeThreshold : 10,
    MaxAgeThreshold : 30,
   StartDate: "12/10/2014",
}]

我想在 MinAge 的验证最小值中使用 MinAgeThreshold 值,如下所示:-

schema: {
               model: {
                 id: "CourseID",
                 fields: {
                    CourseID: { editable: false, nullable: true },
                    StartDate: { editable: false, nullable: true },
                    CourseName: { editable: false, nullable: true },
                    MinAgeThreshold: { editable: false, nullable: true },
                    MinAge: { type: "number", validation: { required: true, min: MinAgeThreshold}                        },
                    MaxAge: { type: "number", validation: { required: true, min: 1} },

                 }

这有可能吗?

我试图在这样的验证自定义函数中使用

MinAge: {
                                type: "number",
                                validation: {
                                    required: true,
                                    minagevalidation: function (input) {
                                }
                            },

但我无法在 minagevalidation 函数中检索 MinAgeThreshold 的值。

任何帮助将不胜感激。

问候

4

2 回答 2

1

您可以尝试以下给出的自定义验证消息,并强制用户根据同一剑道网格中的其他输入字段设置大于最小值的值。

 MinAge: { type: "number",
                    validation: { 
                    required: true, 
                    MinAgevalidation: function (input) {
    if(input.is("[name='MinAge']") &&(parseInt($("input[type='text'][name='MinAge']").val()) < parseInt($("input[type='text'][name='UnitPrice']").val()))){
    input.attr("data-MinAgevalidation-msg", "MinAge should greater than MinAge threshold");

            return false;
    }

    return true;  
    }  

示例 jsfiddle 根据其他字段的值设置一个字段的最小值。

于 2014-08-17T20:05:53.763 回答
0

我想我可能有解决这类问题的办法。如果要通过不同字段的值设置字段的最大值,可以将其添加到 kendogrid 的网格编辑方法中。

var grid = $("#grid").kendoGrid({
    edit: function(e){
        if ( e.container.find("input[data-find='value:MinAge']).length != 0 ){
            var numericTextBox = e.container.find("input[data-find='value:MinAge']).data("kendoNumericTextBox");
            numericTextBox.min(e.model.MinAgeThreshold);
        }
    }   
});

这会将 MinAge 输入的 numerictTextBox 设置为行(模型)的 dataItem 中的 MinAgeThreshold 的最小值。这也适用于 step、max 等。输入字段时触发编辑。因此,如果初始值为 0 并且您的 MinAgeThreshold 是其他值,它将切换到 MinAgeThreshold。

于 2015-04-21T11:44:32.540 回答