Skip to content Skip to sidebar Skip to footer

Knockout Change While Jquery Datepicker Is Open Breaks Datepicker

I've set up a jsFiddle to demonstrate my problem. What I'm doing: I'm using Knockout with a jQuery Datepicker as shown in this question. My model contains an observableArray which

Solution 1:

Note: This answer isn't complete. However, as it's too large for a comment and probably helpful (towards a solution) anyhow I've taken the liberty and posted it as an answer. Anyone that can complete this answer is invited to do so through an edit or by spinning off into another better answer.


The thing that seems to be spoiling the party (taken from the documentation, emphasis mine):

This will be called once when the binding is first applied to an element, and again whenever the associated observable changes value.

If I hackisly prevent the update from doing its datepicker calls in the first update the datepicker won't break anymore (other issues do arise though). For the init I've added this line at the end:

element.isFirstRun = true;

Then the update method will do the following just before the datepicker calls:

if (element.isFirstRun) {
    $(element).val(value);
    element.IsFirstRun = false;
    return;
}    

See this updated fiddle for the results, which are:

  • the mentioned scenario now updates the correct textbox (a good thing);
  • the initial value is now a more verbose DateTime string and stays that way after updates (kinda not nice);

Hopefully this will help towards a more complete solution.

Post a Comment for "Knockout Change While Jquery Datepicker Is Open Breaks Datepicker"