Telerik MVC DatePicker - 禁用所有未来日期 [英] Telerik MVC DatePicker - Disable all future dates

查看:39
本文介绍了Telerik MVC DatePicker - 禁用所有未来日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Telerik MVC DatePicker:

<%: Html.Telerik().DatePickerFor(model => model.Date)
                         .TodayButton()
                         .Max(DateTime.Now)
                         .HtmlAttributes(new { @onkeypress = "return allowNumbersWithDot(event);", @onpaste = "return false;" })
                        %>  

通过设置 Max 属性,我只获取当前日期之前的日期,并且隐藏所有未来日期.我是什么,启用当前日期之前的所有日期并禁用所有未来日期.即用户可以看到所有日期,但只能选择到当前日期.

By setting Max property, I get dates only till current date and all future dates are hidden. What I what is, enable all dates till current date and disable all future dates. i.e. user can see all dates but can select only till the current date.

推荐答案

Max 属性阻止选择和出现值集之后的所有日期.要解决此问题,请尝试使用以下客户端事件处理程序格式化 DatePicker:

The Max property blocks the selection and appearance of all dates after the value set. To get around this, try formatting your DatePicker with a client event handler like:

@Html.Telerik().DatePickerFor(model => model.Date).ClientEvents(e => e.OnChange("onChange"))

然后用这样的东西添加你的验证:

and then add your validation with something like this:

function onChange(e) {
    var endDate = new Date(); // Your specific date
    if (e.value > endDate) {
        if (e.previousValue === null) {
            $(this).data("tDatePicker").value(null);
        }
        e.preventDefault();
    }
}

有关此技术的更多信息可以在 Telerik 支持论坛中找到:http://www.telerik.com/community/forums/aspnet-mvc/datepicker/datepicker---prevent-future-date-selection.aspx

More information about this technique can be found in the Telerik support forums at: http://www.telerik.com/community/forums/aspnet-mvc/datepicker/datepicker---prevent-future-date-selection.aspx

这篇关于Telerik MVC DatePicker - 禁用所有未来日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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