I'm trying to replace a MS AJAX.NET autocomplete control with
something a bit lighter and more cache-and-compress friendly and I
really love how smoothly the Autocomplete plug-in generally works
(http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/).  I
had to change a couple of things to make it work with our JSON-service-
based design:

1) Our application is using web services serialized to JSON and it's
working great up until the autocomplete.  You can read about the
general methodology thanks to Dave over at
http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/.
To get around that for proof-of-concept purposes, I went into
Autocompleter.request and replaced the existing AJAX call with

                $.ajax({
                    type: "POST",
                    url: "ajaxProxy.asmx/TagAutocomplete",
                    data: '{ "prefixText" : "' + lastWord(term) + '",
"count" : ' + options.max + '}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function(msg) {
                        var mashed = options.parse && options.parse
(msg.d) || parse(msg.d);
                        cache.add(term, mashed);
                        success(term, mashed);
                    }
                });

and altered parse() to just take an array instead of a delimited
string (var rows = data; // = data.split("\n");).  Now we're currently
just returning an array of strings, so this is no problem for us (so
long as a user doesn't stick a | or " in terms, though that can likely
be modded out as well).

Question at this point: Is there a simpler way to get the same JSON
callback out of Autocomplete?  If not, given the above, can it be
added to the official source?

2)  Given the above, there was an odd behavior in starting a new term
in a multiple-term box -- toss in a ", " and the correct form of the
previous term shows up ready to be auto-completed.  I fixed that by
eliminating the "0-character word" check (//if ($.trim(value))) in
trimWords such that an empty string can go into the array.  It was a
quick fix, but I'm not sure how solid -- the core symptom appears to
be that lastWord is treating a 0-length word as not a word and instead
skipping to the previous word when onChange is figuring out what to
suggest autocompletes.

Question at this point:  Did I find a bug?  If so, is eliminating that
length-check when making an array of terms the most effective way of
dealing with it?  If so, is this something that will be patched in the
near future?

Thanks!

Reply via email to