You need to bind some viewModel attribute to the datepicker binding ... You overdo this part.
But you need to do some special handling when the datepicker changes the value of the element, because otherwise it will ruin the way when the knockout usually catches the change.
Set up a binding like this ...
HTML:
<div id="accordion" data-bind="jqAccordion:{},template: {name: 'task-template',foreach: Tasks,afteradd: function(elem){$(elem).trigger('valueChanged');}}">. </div>
<script type="text/html" id="task-template">
<div data-bind="attr: {'id': 'Task' + TaskId}" class="group">
<h3><b><input name="TaskName" data-bind="value: TaskName /></b></h3>
<p>
Due Date: <input class="datepicker" data-bind="myDatepicker : taskDueDate" />
</p>
</div>
</script>
:
ko.bindingHandlers.myDatepicker = {
init: function(element, valueAccessor) {
var unwrappedObs = valueAccessor();
$(element).val(ko.unwrap(unwrappedObs));
$(element).datepicker({
changeMonth: true,
changeYear: true
});
ko.utils.registerEventHandler(element, "change", function () {
var unwrappedObs = valueAccessor(),
val = $(element).datepicker("getDate");
unwrappedObs(val);
});
}
};
:
http://jsfiddle.net/brettwgreen/nmb6c6gq/