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

KendoDate issue with value()

2 Answers 112 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Guillermo
Top achievements
Rank 1
Guillermo asked on 11 Sep 2012, 07:22 PM
Hello,

I noticed that you can set the value of the date picker using a date or a string with the proper format. If i use the date, I'm getting a different behaviour form the string, when I first put the text to the input

I have created the control with a change event option.

I'm setting the value of the control this way:

datepicker.value(new Date());

when i'm writing some invalid date in the input, the expected behaviour will be that the change event is not executed. But it's being executed.

I tested it with setting the value with a string:

datepicker.value("1/9/2011"); 

and the result is the expected. the event is not executed.

example:

           <div id="Div6" class="k-content">
            <div id="email-settings">
                <div id="test" style="margin-top: -6px; margin-left: 180px">
                    <input id="datepicker" style="width:150px;" />
                </div>
                <div style="margin-top: 59px; margin-left: 180px">
                    <input id="monthpicker" value="10/10/2011" style="width:150px" />
                </div>
            </div>
        <script>
        $(document).ready(function () {
        // create DatePicker from input HTML element
        $("#datepicker").kendoDatePicker({
        change: function () {
        // get widget
        var widget = this;
        alert("datepicker");
        }
        });
        $("#monthpicker").kendoDatePicker({
        change: function () {
        // get widget
        var widget = this;
        alert("monthpicker");


        }
        });




        var datepicker = $("#datepicker").data("kendoDatePicker");
        var a = "1/9/2011";
        datepicker.value(a);


        var monthpicker = $("#monthpicker").data("kendoDatePicker");
        var b = new Date();
        monthpicker.value(b);
        });
        </script>



Regards 

2 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 12 Sep 2012, 10:07 AM
Hello Guillermo,

 
The described behavior is expected. When you set value with value(new Date()),  the set date is something like this "Sep 1 2012 10:29:09". Note the time part, but the input value will be "9/1/2012". When you focus and then blur the input, the parsed Date will be "Sep 1 2012 00:00:00". This is considered as a change and the change event is triggered. If you need to persist the time, then you will need to use the DateTimePicker widget.

Regards,
Georgi Krustev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Guillermo
Top achievements
Rank 1
answered on 13 Sep 2012, 01:30 PM
thanks you very much!

regards
Guillermo
Tags
Date/Time Pickers
Asked by
Guillermo
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Guillermo
Top achievements
Rank 1
Share this question
or