knockout-bootstrap icon indicating copy to clipboard operation
knockout-bootstrap copied to clipboard

Typeahead not binding automatically back to Knockout ViewModel

Open codepic opened this issue 12 years ago • 1 comments

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.

codepic avatar Jul 10 '13 08:07 codepic

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

billpull avatar Jul 11 '13 14:07 billpull