All,
Environment:
asp.net 3.5
My dates are serialized using ISO8601 format via lib: Newtonsoft.json library
Objective:
Create 2-way binding between a date field on my model (Document.DocumentDate) and the textbox of the ajax control toolkit calendar extender. The ajax calendar uses a text field behind the scenes so I apply the binding below to the text field. When the page loads, the binding from object to control works but after I change the text field using the calendar extender, the text value is changed but my underlying object is not updated, neither the update() method on the binding is called.
Here's the code:
data-bind="date: {jsonDate : Document.DocumentDate }"
ko.bindingHandlers.date = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var value = valueAccessor();
var dtStr = ko.unwrap(value.jsonDate);
var dt = new Date(dtStr);
var ret = dt.getMonth() + 1 + "/" + dt.getDate() + "/" + dt.getFullYear();
$(element).val(ret);
},
update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
}
};
NOTE:
If I change my data-bind expression to:
data-bind="value: Document.DocumentDate"
Everything works fine but the date gets rendered not the way I wanted in the text field. That's why I resorted to custom binding to format the date in the text field.