GANI
GANI

Reputation: 2049

set the max date on kendo date picker from client side

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.

Upvotes: 7

Views: 20583

Answers (4)

Ajay2707
Ajay2707

Reputation: 5798

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.

Upvotes: 0

DontVoteMeDown
DontVoteMeDown

Reputation: 21465

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

Upvotes: 14

GANI
GANI

Reputation: 2049

It worked this way also

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

Upvotes: 1

Kylok
Kylok

Reputation: 769

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

Upvotes: 4

Related Questions