TrueEddie
TrueEddie

Reputation: 2233

Knockout not updating on input value changed with datepicker

So I have to collect a date and time from the user. I want to be able to set both from a single picker. I found this nice one by curious solutions here. Our site uses jQuery, jQuery mobile, and Knockout. When I use the datepicker to select the date my knockout binded variable is not updating, even though the value of the input box has changed. If I use jQuery to get the value it shows up just fine.

So my question: Can someone help me figure out how to get my knockout binding to update?

I've already tried setting the valueUpdate to input, and afterkeydown with no luck.

Here is a link to a fiddle I made that demonstrates the problem: http://jsfiddle.net/TrueEddie/eg6zM/

Upvotes: 1

Views: 957

Answers (1)

RP Niemeyer
RP Niemeyer

Reputation: 114792

In the plugin, when the value of the element is set it needs to trigger the change event.

Something like:

_setValueOfElement: function(sElemValue)
{
    var dtPickerObj = this;

    var $oElem = $(dtPickerObj.dataObject.oInputElement);
    if(dtPickerObj._compare($oElem.prop("tagName"), "INPUT"))
        $oElem.val(sElemValue);
    else
        $oElem.html(sElemValue);

    //ADDED THIS LINE
    $oElem.change();

        return sElemValue;
},

The plugin doesn't seem to have any eventing built-in, so doesn't look like there is a good way to react to the value being set otherwise.

Upvotes: 2

Related Questions