Code Junkie
Code Junkie

Reputation: 7788

Upgrading typeahead from 0.9.3 to 0.10.5 remote

Hi I'm having troubles upgrading my typeahead js from 0.9.3 to 0.10.5. It worked in 0.9.3, but I can't seem to get my remote connection working in the latest version.

I'm using the following code.

init = function(spec) {
    var $field;

    $field = $(document.getElementById(spec.id));

    var suggestions = new Bloodhound({

        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
        queryTokenizer: Bloodhound.tokenizers.whitespace,

        remote: {
            url: spec.url,
            replace: function(uri, query) {
                return extendURL(uri, {
                    "t:input": query
                });
            },
            filter: function(response) {
                return response.matches;
            }
        }
    });

    suggestions.initialize();

    return $field.typeahead({
        limit: 5,
        displayKey: 'value',
        source: suggestions.ttAdapter()
    });
};
return exports = init;

in 0.9.2 the following code worked, but for some reason every time you did a key down in the input box, the suggestions disappeared until keyup with a match. I'm hoping this upgrade will fix my issue or perhaps there was a configuration issue that caused it.

init = function(spec) {
    var $field;

    $field = $(document.getElementById(spec.id));
    return $field.typeahead({
        minLength: spec.minChars,
        limit: 5,
        remote: {
            url: spec.url,
            replace: function(uri, query) {
                return extendURL(uri, {
                    "t:input": query
                });
            },
            filter: function(response) {
                return response.matches;
            }
        }
    });
};

Upvotes: 0

Views: 691

Answers (1)

Code Junkie
Code Junkie

Reputation: 7788

I was missing the null in the constructor.

return $field.typeahead({
        limit: 5,
        displayKey: 'value',
        source: suggestions.ttAdapter()
});

Fixed version

return $field.typeahead(null, {
        minLength: spec.minChars,
        displayKey: 'value',
        source: suggestions.ttAdapter(),
});

Upvotes: 1

Related Questions