This is a migrated thread and some comments may be shown as answers.

Can i disable previous dates on Html.Kendo().DatePicker()

1 Answer 985 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Jeena
Top achievements
Rank 1
Jeena asked on 08 Mar 2013, 05:31 AM
I am using Html.Kendo().DatePicker()
I have a requirement to disable the previous dates (i.e dates > today)

Is it posisble, if so how? Also what if the model contains a value > today

Is it possible to achieve both with Kendo datePicker

1 Answer, 1 is accepted

Sort by
0
Dimiter Madjarov
Telerik team
answered on 11 Mar 2013, 01:55 PM
Hi Jeena,

You could use the Min method to specify the minimal date which can be selected in the picker. In the current scenario you should specify:

.Min(DateTime.Today)

Regarding your second question, what do you mean by "if the model contains a value > today"?
  Regards,
Dimiter Madjarov
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Mani
Top achievements
Rank 1
Iron
commented on 24 Jun 2023, 07:17 AM

Hii Dimiter Madjarov

But if we are adding .Min(DateTime.Today) The previous dates are not showing we want to show the previous dates also

but those want to be disable. it means the user cannot able to select the previous date for that how we can add a code

 

Thanks and Regards

Aleksandar
Telerik team
commented on 28 Jun 2023, 04:19 AM

The DatePicker exposes a DisableDates configuration method that has several overloads. An approach to disable weekends or specific dates are demonstrated in the Disabled Dates Demo. Make sure to click on the View source tab to review the entire implementation. If  you want to disable all date prior to today, for example, you can do so by passing name of the JavaScript handler function to the DisableDates configuration method. The function will be dynamically resolved for each date of the calendar. Note that when the function returns true, the date will be disabled.
<div class="k-d-flex k-justify-content-center" style="padding-top: 54px;">
    <div class="k-w-300">
        @(Html.Kendo().DatePicker()
                .Name("picker")
                .DisableDates("disableDates")
            )
    </div>
</div>

<script>
    function disableDates(date) {
        var today = new Date()

        if (date < today) {
            return true;
        } else {
            return false;
        }
    }
</script>
Tags
Date/Time Pickers
Asked by
Jeena
Top achievements
Rank 1
Answers by
Dimiter Madjarov
Telerik team
Share this question
or