KendoUI DatePicker validation when multiple date f

2019-08-16 16:55发布

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条回答
Summer. ? 凉城
2楼-- · 2019-08-16 17:23

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

查看更多
登录 后发表回答