0

I am using the following code:

$(function(){
        $(".aucomplete").live("keyup", function(){
            var all_analysts = [<TMPL_VAR ALL_TARGETS>];
            $(this).autocomplete({
                    source: all_analysts, //local lookup values
                    delay: 0
            });
        });
    });

and "ALL_TARGETS" contains a string like: 'X','Y','Z'.

When limiting the string to 1000 items, everything works fine. When limiting the string to 5000 items, aucomplete doesn't work and on chrome I get the following error: "Uncaught SyntaxError: Unexpected string" (under the "var all_analysts = [];" row).

(firefox and Iexplorer don't show the error but aucomplete still doesn't work).

Anyone know what may be the broblem?

Thanks in advance.

2 Answers 2

1

A workaround would be to use the remote feature to bypass any limit

$(function(){
        $(".aucomplete").live("keyup", function(){
            var all_analysts = [<TMPL_VAR ALL_TARGETS>];
            $(this).autocomplete({
            minLength: 2,
            source: function( request, response ) {
                var term = request.term;
                if ( term in cache ) {
                    response( cache[ term ] );
                    return;
                }
                //Return part of your big array
                $.getJSON( "search.php", request, function( data, status, xhr ) {
                    cache[ term ] = data;
                    response( data );
                });
            },
            delay: 0
            });
        });
    });

Check JQueryUI docs, there are several remote functionalities http://jqueryui.com/autocomplete/#remote-with-cache

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry, but I new with this plugin. should I actually copy-paste the code as is? How should the values (ll_analysts) pass to the source? Thanks
Find a basic implementation tutorial here : simonbattersby.com/blog/…
1

I think your problem is with the source attribute of the autocomplete, in jquery autocomplete the source isn't the list it will search inside but it's the path to the server that will respond with a json list including the results so in your case it should look similar to this

$(function(){
    $(".aucomplete").each( function(){
        var all_analysts_path = /path/to_your/server_side_method_or_controller;
        $(this).autocomplete({
                source: all_analysts_path, //local lookup values
                delay: 0
        });
    });
});

3 Comments

What exactly is the path: "/path/to_your/server_side_method_or_controller? is it a file? what should be its syntax? thanks!
It depends on the technology you are using, for example if you are using an MVC based one then it's a path to your controller that renders json, it should be a normal href close to /analysts/search
plus that you don't need to use live keyup event that's what the plugin does you just need to say .each like what I've edited above in the code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.