Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

relating two kendo date pickers to make sure To date is always greater than or equal to From date

is there any default way in kendo DatePicker for ensuring (and alerting user accordingly) that To date is always greater than or equal to From date.

like image 852
StarDust Avatar asked Nov 19 '25 01:11

StarDust


1 Answers

There is no default way but there is one example in Kendo UI demos page that might help you. Read here

Basically given this HTML:

<div class="demo-section" style="width:470px">
    <label for="start">Start date:</label>
    <input id="start" value="10/10/2011"/>

    <label for="end" style="margin-left:3em">End date:</label>
    <input id="end" value="10/10/2012"/>
</div>

And this DatePicker initialization:

var start = $("#start").kendoDatePicker({
    change: startChange
}).data("kendoDatePicker");

var end = $("#end").kendoDatePicker({
    change: endChange
}).data("kendoDatePicker");

start.max(end.value());
end.min(start.value());

They suggest the following startChange and endChange functions:

function startChange() {
    var startDate = start.value();

    if (startDate) {
        startDate = new Date(startDate);
        startDate.setDate(startDate.getDate() + 1);
        end.min(startDate);
    }
}

function endChange() {
    var endDate = end.value();

    if (endDate) {
        endDate = new Date(endDate);
        endDate.setDate(endDate.getDate() - 1);
        start.max(endDate);
    }
}
like image 92
OnaBai Avatar answered Nov 22 '25 02:11

OnaBai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!