Reputation: 6151
I'm using the Keith Wood Jquery Date Picker along with Knockout JS. This can be seen here:
$(function () {
$('#popupDatepicker').datepick();
});
function AppViewModel() {
this.dateString = ko.observable("10/10/2010");
}
// Activates knockout.js
ko.applyBindings(new AppViewModel());
When I change the textbox the knockout binding is updated appropriately. However when the datepicker is used knockout does not register the change. How can I resolve this?
Upvotes: 2
Views: 252
Reputation: 2374
This fiddle show a working example. Basically, you need to set the value in the onSelect
event of the DatePicker.
var viewModel;
$(function () {
viewModel = new AppViewModel();
// Activates knockout.js
ko.applyBindings(viewModel);
$('#popupDatepicker').datepick({
onSelect: function(dates) {
var minDate = dates[0];
viewModel.dateString($.datepick.formatDate(minDate));
}
});
});
// This is a simple *viewmodel* - JavaScript that defines the data and behavior of your UI
function AppViewModel() {
this.dateString = ko.observable("10/10/2012");
}
Upvotes: 2