KendoUI DatePicker validation when multiple date fields are on a page

烈酒焚心 提交于 2019-12-25 03:08:36

问题


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...

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?


回答1:


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

Your JSBin modified here



来源:https://stackoverflow.com/questions/16970827/kendoui-datepicker-validation-when-multiple-date-fields-are-on-a-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!