将 jquery 验证添加到 kendo ui 元素 [英] adding jquery validation to kendo ui elements

查看:26
本文介绍了将 jquery 验证添加到 kendo ui 元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了很多关于此的帖子,并且在添加以下内容时它确实可以验证我的字段.

I've looked at many posts on this and have it working to the extent that it does validate my fields when I add the following.

$.validator.setDefaults({
    ignore: []
});

我仍然缺少的部分是添加 input-validation-error 类来通知用户.它适用于我的其他输入元素(非剑道).我也尝试在 $.validator.setDefaults 中手动添加类,但似乎没有任何效果.

The part I'm still missing is adding the input-validation-error class to notify the user. It is working fine for my other input elements (non-kendo). I've tried adding the class manually in $.validator.setDefaults as well but nothing seems to be working.

是否有任何地方的示例或有人让它工作?

Is there an example out there somewhere or has anyone gotten it to work?

我不确定我这样做是否正确,但这是我尝试手动添加的内容.

I'm not certain I'm doing this right but here's what I've tried to add it manually.

$.validator.setDefaults({
    ignore: [],
    errorClass: "input-validation-error",
    errorElement: "input",
    highlight: function (element, errorClass) {
        $(element).addClass(errorClass)
    },
    unhighlight: function (element, errorClass) {
        $(element).removeClass(errorClass)
    }
});

推荐答案

我找到了一个基于 这篇文章.基本上你需要做的是寻找包裹 input 的父元素.像这样:

I found a solution to this based on this post. Basically what you need to do is look for the parent element that the input is wrapped in. Something like this:

$.validator.setDefaults({
    ignore: [],
    highlight: function (element, errorClass) {
        element = $(element);
        if (element.parent().hasClass("k-widget")) {
            element.parent().addClass('input-validation-error');
        } else {
            element.addClass('input-validation-error')
        }
    },
    unhighlight: function (element, errorClass) {
        element = $(element);
        if (element.parent().hasClass("k-widget")) {
            element.parent().removeClass('input-validation-error');
        } else {
            element.removeClass('input-validation-error')
        }
    }
});

我会建议任何人在离开这个特定的兔子洞之前访问我上面链接的帖子,因为它引入了另一个问题,只是为了了解您正在进入的内容.例外的答案确实比那里被问到的问题与这个问题更相关.

I would advise anyone though to visit the post I've linked to above before taking off down this particular rabbit hole as it introduces another issue, just to be aware of what you're getting into. The excepted answer is really more relevant to this question than the one being asked there.

这篇关于将 jquery 验证添加到 kendo ui 元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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