Max
Max

Reputation: 4405

Knockout.js doesn't pick up autocompleted or prefilled values

I've noticed that Knockout doesn't seem to update my view model when I use autocomplete (remembering password, for example).

I read that there was an issue with this, but should have been fixed by now. It doesn't seem to be working for me though.

I've hosted a mini-example of the problem, if you fill in random string + password, press save and "remember password" and use the autocomplete feature the observables email and password doesn't get updated until you focus the relevant textbox and then leave focus.

This is tested using IE 9 or Firefox 18.

The reason I don't use fiddle is because I didn't seem to be able to trigger the autocomplete feature.

Any ideas?

http://cyberrascal.no-ip.org/tempsite

Upvotes: 2

Views: 611

Answers (1)

Anders
Anders

Reputation: 17554

The value is overwritten by the value binding, please have a look at this fiddle http://jsfiddle.net/rniemeyer/TeFAX/

ko.bindingHandlers.valueWithInit = {
    init: function(element, valueAccessor, allBindingsAccessor, context) {
        var observable = valueAccessor();
        var value = element.value;

        observable(value);   

        ko.bindingHandlers.value.init(element, valueAccessor, allBindingsAccessor, context);
    },
    update: ko.bindingHandlers.value.update
};

Also you must wait until the value is set by the browser

setTimeout(function() { ko.applyBindings(viewModel); }, 15);

Upvotes: 3

Related Questions