Twitter typeahead.js not initializing / working as expected using remote data source

88 Views Asked by At

Twitter typeahead not working as expected, when I comment out code in the library I do get a non-styled drop down of suggestions.

    jQuery('input#test').typeahead(
    {
        hint: true,
        highlight: true,
        limit:25, //still using 5 which is default in the library
        minLength: 3
    },
    {
        name: 'customLookup',
        source: function(query, result) {
            return jQuery.ajax({
                url: url, //my dynamic url, returns custom json array that needs to be mapped
                data: 'shop_name=' + query + "&limit=25", //custom limit against backend api
                dataType: "json",
                type: "post",
                success: function(data, textStatus, xhr) {
                    var suggestions = [];
                    
                    jQuery.map(data.data, function(item){
                        suggestions.push(item.name + " - " + item.address);
                    });

                    result(suggestions); //stepping in, it just skips because syncCalled already = true? Then remove that code and it gives me back a list of 5 that isn't styled...

                    console.log(suggestions); //has array of strings as expected
                },
                error: function (request, status, error) {
                    alert(error);
                }
            });
        }
    });

So are there options or updates I've missed capturing when configuring? Using a back end custom data source that needs JSON mapped to an array for typeahead.

1

There are 1 best solutions below

0
fr332lanc3 On

Just ended up modifying the library directly and having our own copy, not sure the issue but seems to work fine with that approach and using custom CSS to style.