billpull / knockout-bootstrap

A plugin that adds custom bindings for twitter bootstrap objects such as tooltips and popovers.
233 stars 69 forks source link

Typeahead not binding automatically back to Knockout ViewModel #16

Open codepic opened 11 years ago

codepic commented 11 years ago

Here's a JsFiddle to describe the issue: http://jsfiddle.net/codepic/v4bC4/

You can see when I'm selecting something from the typeahead list, it's not really binding back to model.

However if I change the updater in the typeahead binding like so, it starts working:

// Bind twitter typeahead
ko.bindingHandlers.typeahead = {
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) {
    var $element = $(element);
    var allBindings = allBindingsAccessor();
    var typeaheadArr = ko.utils.unwrapObservable(valueAccessor());

    $element.attr("autocomplete", "off")
            .typeahead({
                'source': typeaheadArr,
                'minLength': allBindings.minLength,
                'items': allBindings.items,
                // 'updater': allBindings.updater
                'updater': function(item) {
                     allBindings.value(item);
                     return item;
                 }
            });
}
};

I'm not sure if this is an issue or just me using the binding wrong. I tried to go through the docs but it didn't help much.

billpull commented 11 years ago

Yea this looks like a bug I will incorporate your changes.