【问题标题】:Kendo UI Grid inline edit define custom values for min validationKendo UI Grid 内联编辑为最小验证定义自定义值
【发布时间】:2014-08-17 10:10:47
【问题描述】:

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

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

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 的值。

任何帮助将不胜感激。

问候

【问题讨论】:

    标签: validation kendo-ui kendo-grid inline-editing custom-validators


    【解决方案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;  
        }  
    

    sample jsfiddle to set minimum value of one field based on other field's value .

    【讨论】:

      【解决方案2】:

      我想我可能有解决这类问题的办法。如果您想通过不同字段的值设置字段的最大值,您可以将其添加到 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。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-14
        • 1970-01-01
        • 1970-01-01
        • 2013-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多