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

Manually force update of value() for DatePicker

1 Answer 536 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
David A.
Top achievements
Rank 1
David A. asked on 22 May 2013, 05:35 PM
Hi,

I have a datepicker that I am using to increment/decrement the day by using the up/down arrow by binding the keypress event.  This works fine unless the user types in a new date before leaving the datepicker and then hits the up/down arrow in which case the value() is not updated.  What I want to do is upon an up/down arrow keypress, FIRST update the value() and then increment/decrement the day.  How can I do this?

My js is as follows:
$("#thedatePicker").on("keydown", function(e) {
        var keyCode = e.keyCode || e.which;
        var day=0;
         
        if (keyCode == 38) {
            e.preventDefault();
            day=1;
        }
        else if (keyCode == 40) {
            e.preventDefault();
            day=-1;
        }
        else
            return;
 
        var picker = $(this).data("kendoDatePicker");
 
        // update value() here in the event the user manually typed a new date
 
        var dateVal = picker.value();
 
        if (dateVal == null)
            return;
 
        dateVal.setDate(dateVal.getDate() + day);
 
        picker.value(dateVal);
    });


Thank you,
David A.

1 Answer, 1 is accepted

Sort by
0
Accepted
Georgi Krustev
Telerik team
answered on 23 May 2013, 12:57 PM
Hello David,

You can parse the value of the input in the keydown event handler like this:
 

//instead of this
//var dateVal = picker.value();
var date = kendo.parseDate(picker.element.val(), picker.options.parseFormats);

Regards,
Georgi Krustev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Date/Time Pickers
Asked by
David A.
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or