最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - set the max date on kendo date picker from client side - Stack Overflow

programmeradmin4浏览0评论

I have this:

var today = new Date();

Updating the kendo datepicker:

$('#datepicker').kendoDatePicker({
    max: today.setDate(today.getDate()+30);
});

In the debugger the max value is 1404408808080 but in today variable the date is right one 2014-07-03T17:3. Want to set the max date for kendodatepicker 30 days from the current date.

I have this:

var today = new Date();

Updating the kendo datepicker:

$('#datepicker').kendoDatePicker({
    max: today.setDate(today.getDate()+30);
});

In the debugger the max value is 1404408808080 but in today variable the date is right one 2014-07-03T17:3. Want to set the max date for kendodatepicker 30 days from the current date.

Share Improve this question edited Jun 3, 2014 at 17:49 DontVoteMeDown 21.5k10 gold badges71 silver badges113 bronze badges asked Jun 3, 2014 at 17:42 GANIGANI 2,0495 gold badges36 silver badges70 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 14

You have to use the setOptions() method to change that:

var datepicker = $("#datepicker").data("kendoDatePicker");

datepicker.setOptions({
    max: new Date(today.setDate(today.getDate()+30))
});

Or if you want just do this in the initialization:

$("#datepicker").kendoDatePicker({
    max: new Date(today.setDate(today.getDate()+30))
});

The setDate function returns the date as an integer (the long number you posted); try sending that as a parameter to a new Date object, like so:

$('#datepicker').kendoDatePicker({
    max: new Date(today.setDate(today.getDate()+30));
});

It worked this way also

         var today = new Date();
         var maxDate = today.setDate(today.getDate()+30);
         $('#datepicker').kendoDatePicker({
         max: new Date(maxDate) });

I think this is the simplest way (as per Kendo document too)

<input id="datepicker" />
<script>
$("#datepicker").kendoDatePicker();

var datepicker = $("#datepicker").data("kendoDatePicker");

datepicker.max(new Date(2100, 0, 1));
</script>

Added a dojo example where see how we restrict (minimum and maximum date example) the birthdate and deceased date of a patient entry.

发布评论

评论列表(0)

  1. 暂无评论