当页面上有多个日期字段时,KendoUI DatePicker 验证 [英] KendoUI DatePicker validation when multiple date fields are on a page

查看:26
本文介绍了当页面上有多个日期字段时,KendoUI DatePicker 验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望验证页面上的日期字段,这很简单(请参阅此 JSBin).但是,当页面上有多个日期字段时,事情开始变得古怪...

I'm looking to validate date fields on a page, which is simple (see this JSBin). BUT, when a page has multiple date fields on a page things start to get wacky...

请参阅此 JSBin 并处理无效日期.

See this JSBin and play around with invalid dates.

无效消息不知道要绑定到哪个输入,从而导致错误输入的错误消息.有没有办法触发正确的输入字段?

The invalid message doesn't know which input to bind to, causing error messages on the wrong inputs. Is there a way to trigger the correct input field?

推荐答案

不是为表单定义验证器,而是为每个日期定义一个验证器,因为您实际上要验证字段而不是整个表单.你可以这样做:

Instead of defining a validator for the form, define a validator for each date as actually you want to validate the fields and not the form as a whole. You can do it as:

$(".datepicker").kendoDatePicker();
$(".datepicker").kendoValidator({
    rules   : {
        //implement your custom date validation
        dateValidation: function (e) {
            console.log("e", e);
            var currentDate = Date.parse($(e).val());
            //Check if Date parse is successful
            if (!currentDate) {
                return false;
            }
            return true;
        }
    },
    messages: {
        //Define your custom validation massages
        required      : "Date is required message",
        dateValidation: "Invalid date message"
    }
});

您的 JSBin 已修改此处

Your JSBin modified here

这篇关于当页面上有多个日期字段时,KendoUI DatePicker 验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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