首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Kendo-Grid列字段验证

Kendo-Grid列字段验证
EN

Stack Overflow用户
提问于 2014-07-10 16:11:22
回答 3查看 22.7K关注 0票数 5

我正在致力于用API数据填充kendo--grid,但在一个字段上添加验证也会自动适用于其他所有字段。

下面是kendo-dataSource中的模式:

代码语言:javascript
复制
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'}
                       }
                   }
                },  

在这里,我为标题字段添加了验证,但它也被其他字段调用。我正在添加一个验证快照

请帮我找出其中的错误。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-07-10 22:11:31

您的代码中实际上没有任何错误,但更像是Kendo Grid的验证设计中的错误。即使您仅在title字段中指定验证函数,它也会对您编辑的任何输入字段全局运行验证。

validateTitle中,您需要过滤希望在哪个输入上运行验证函数。如下所示:

代码语言:javascript
复制
if (input.is("[name='title']") && input.val().length > 5) {
    input.attr("data-validateTitle-msg", "Max length exceeded 5 characters only");
    return false;
}

如果你需要一个现场工作演示,你可以随时参考Telerik的在线演示,它是可编辑的,非常方便地玩东西。下面是用于自定义验证的,它们同样需要过滤输入的字段名。

票数 6
EN

Stack Overflow用户

发布于 2017-01-20 20:08:36

您只想要必填字段验证,即只需添加视图模型属性属性

代码语言:javascript
复制
[Required(ErrorMessage ="CountryCode is Mandatory")]
        public virtual string CountryCode
        {
            get;
            set;
        }
票数 3
EN

Stack Overflow用户

发布于 2018-09-23 17:07:52

我们可以很容易地使用此代码设置最大长度,它将不允许用户输入超过指定的字符

代码语言:javascript
复制
  model: {
                    id: "CLASSID",
                    fields: {
                        CLASSID: { type: "number" },
                        CLSNAME: { type: "string" },
                        CLSFLAG: {
                            type: "string", validation: {
                                required: true,maxlength:"3"
                            }
                        },
                        CLSSTATUS: { type: "boolean" }
                    }
                }
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24671452

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档