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

date inputs and data binding

3 Answers 539 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Ryan
Top achievements
Rank 1
Ryan asked on 19 Jan 2013, 05:11 PM
I'm having a hard time getting a model property of type 'date' to bind to inputs of type 'date', 'datetime', or 'datetime-local'. I think the problem is that these inputs require value to be in a particular format or it gets ignored, but the binding isn't formatting the date properly.
<input type=date> requires 'YYYY-DD-MM'
<input type=datetime> requires 'YYYY-DD-MMTHH:mm:ssZ'
<input type=datetime> requires 'YYYY-DD-MMTHH:mm:ss'

Also I can't tell if it's properly parsing the value from the different types once a date is selected.

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 22 Jan 2013, 01:13 PM
Hello Ryan,

Thank you for getting in touch with us.

By default the value binding will not parse JavaScript objects into the required format. This is why I suggest you to use custom bindings. This example demonstrates how to create a date and datetime-local bindings:

If you want to create month, time or datetime (with time zone) you have to change the format in refresh and change functions:
refresh: function() {
    var that = this,
    value = that.bindings["dateTimeValue"].get(), //get value
    formatedValue = kendo.toString(value, "yyyy-MM-ddTHH:mm"); //format
 
    $(that.element).val(formatedValue); //update the HTML input element
},
change: function() {
    var formatedValue = this.element.value, //get input value
    value = kendo.parseDate(formatedValue, "yyyy-MM-ddTHH:mm"); //parse the value
 
    if (value) {
        this.bindings["dateTimeValue"].set(value); //update the View-Model
    }
}

I hope this will help.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Gonzalo
Top achievements
Rank 1
answered on 27 Feb 2015, 02:41 PM
Thanks for the reply Alexander.
I tried the approach suggested on the link you provided but the problem is that the "change" callback is never invoked, so my view model is never updated with the user-entered data.

Do you know why that callback is not being invoked?
0
Gonzalo
Top achievements
Rank 1
answered on 27 Feb 2015, 02:42 PM
Sorry. Wrong thread.
Tags
General Discussions
Asked by
Ryan
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Gonzalo
Top achievements
Rank 1
Share this question
or