rniemeyer / knockout-jqAutocomplete

knockout-jqAutocomplete is a Knockout.js plugin designed to work with jQuery UI's autocomplete widget.
MIT License
49 stars 20 forks source link

Fails to set input value to inputProp because of ko.deferUpdates (KO 3.4.0+) #39

Open BHare1985 opened 5 years ago

BHare1985 commented 5 years ago

When knockout is running with deferred updates updating the value of the autocomplete https://github.com/rniemeyer/knockout-jqAutocomplete/blob/5cfce82420b3eaf6c7302582c3d5a6fa338c9839/src/knockout-jqAutocomplete.js#L50 & https://github.com/rniemeyer/knockout-jqAutocomplete/blob/5cfce82420b3eaf6c7302582c3d5a6fa338c9839/src/knockout-jqAutocomplete.js#L65 the update event will be deferred and get executed after the value is updated to the inputProp , which in turn sets the value back to the actual value.

Solution is to call ko.tasks.runEarly(); any time the knockout code relies on an event being triggered, such as right after (but not limited to) any options.value call.

Here is a fiddle demonstrating the issue with KO 3.4.2 (latest release): jsfiddle