Link to home
Start Free TrialLog in
Avatar of mainrotor
mainrotor

asked on

Need help assigning a max date value to my Kendo DatePicker control

Hi Experts,
I have an MVC.Net application with C# code behind.
I need help assigning a max date value to my Kendo UI control.
I want the max date to be the current date.  I have tried some code but it's not working (see code below).
What can I do to make this work?

CURRENT CODE THATS NOT WORKING
<script>
    $(document).ready(function () {
        var today = new Date();
        var maxDate = todayx.setDate(today.getDate());

        $("#EndDate").kendoDatePicker({
            max: new Date(maxDate)
        });
    });
</script>


    <table class="aTable" border="0">
        <tr class="aRow">
            <td class="right1">
                To:&nbsp;
                @(Html.Kendo().DatePicker().Name("EndDate")
                .HtmlAttributes(new { @class = "dataPickerStyle", title = "End Date" }))
            </td>
        </tr>
    </table>

Open in new window


Thank you in advance,
mrotor
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try change:

var maxDate = todayx.setDate(today.getDate());

Open in new window


to:

var maxDate = today.getDate();

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Flabio Gates
Flabio Gates

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mainrotor
mainrotor

ASKER

Hi Flabio and Ryan,
I tried both our your suggestions but it still not working.

Sorry that the todayx in m y code caused confusion.  It was left there accidently.  I thought I had cleaned up my code.
This is how my code should look like after further clean up. Ha ha.

<script>
    $(document).ready(function () {
        var today = new Date();
        var maxDate = today.setDate(today.getDate());

        $("#EndDate").kendoDatePicker({
            max: new Date(maxDate)
        });
    });
</script>


    <table class="aTable" border="0">
        <tr class="aRow">
            <td class="right1">
                To:&nbsp;
                @(Html.Kendo().DatePicker().Name("EndDate")
                .HtmlAttributes(new { @class = "dataPickerStyle", title = "End Date" }))
            </td>
        </tr>
    </table>

Open in new window

I didn't use kendoDatePicker but I think Flabio's solution should work for you...

<script>
    $(document).ready(function () {
        var today = new Date();

        $("#EndDate").kendoDatePicker({
            max: today
        });
    });
</script>
Flabio's solution didn't work for me. :-(
Apparently, Kendo is a non-free JQuery plugin. Best you ask their support page.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Question inactive