1

我想在客户端验证剑道 DateTimePickerFor。我的控制视图为

@(Html.Kendo().DateTimePickerFor(m => m.StartDate)
                        .HtmlAttributes(new { style = "width:200px", @class = datePicker",required = "true" })
                        .Name("StartDate")
                        .Depth(CalendarView.Year)
                        .Value(DateTime.Now.ToString())
                        .Min(DateTime.Now.ToString())
                        .Max(DateTime.Now.AddMonths(4))
                        .Format("MM/dd/yyyy hh:mm tt")                        

                )   

我已经在准备好的功能中掩盖了它。但它允许我输入任何输入。

$(document).ready(function () {
    $('.datePicker').mask('99/99/9999');

    $('#_appointmentCreateForm input[type="text"], textarea').tooltipster({
        trigger: 'custom',
        onlyOne: false,
        position: 'right',
        appendTo: "#_appointmentCreateForm"
    });

    $('#_appointmentCreateForm').validate({
        ignore: [],
        rules: {

            StartDate: {
                required: true
            }
        },
        messages: {

            StartDate: {
                required: "Please choose Date and Time."
            }
        },
        errorPlacement: ValidatorErrorPlacement,
        success: ValidatorSuccess
    }
    );

});

当 datetimepicker 中没有值时,即 datetimepicker 为空,则验证失败但不显示任何消息。那么,有什么想法可以验证 Kendo DateTimePicker 以接受有效的输入格式吗?提前致谢。

4

2 回答 2

0

我的问题已经解决了!当我将准备好的功能更改为

$(document).ready(function () {
    $('.datePicker').mask('99/99/9999');

    $('#_appointmentCreateForm input[type="text"], textarea').tooltipster({
        trigger: 'custom',
        onlyOne: false,
        position: 'right',
        appendTo: "#_appointmentCreateForm"
    });

    $('#_appointmentCreateForm').validate({
        ignore: [],
        rules: {
            Speciality: {
                selectspeciality: true
            }
        },
        messages: {
            Speciality: {
                selectspeciality: "Please select Speciality."
            }

        },
        errorPlacement: ValidatorErrorPlacement,
        success: ValidatorSuccess
    }
    );



    $.validator.addMethod("selectspeciality", function (value, element) {
        var isValid = $(element).data("kendoDropDownList").selectedIndex == 0 ? false : true;
        return this.optional(element) || isValid;
    }, "Please select Speciality.");
});    

何[e它会帮助像我这样的人。

于 2014-01-10T11:36:52.503 回答
0

你可以定义

    Html.Kendo().DateTimePickerFor(model => model.date_debut)
    .ParseFormats(new string[] { "dd/MM/yyyy HH:mm" })

在控件上。但这将是服务器端验证,因为 Html.Kendo() 将从模型生成控件。要在客户端验证它,最好的方法是测试何时触发提交。

$.submit(function(e) {
 //test if form is ok
});
于 2014-01-07T13:35:45.090 回答