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

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

问题描述

我已经看过许多关于此的文章,并且在我添加以下内容时可以使其确实验证我的字段.

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)
    }
});

推荐答案

我基于

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.

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

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