A little bug I ran into, and the fix for it that I found, in case
anyone else has similar issues:

I'm using the jQuery Autocomplete plugin, with a JSON data source.

This is done by adding a custom parse method to the initialization, as
such:

input.autocomplete(ac_url, {
            limit: 10,
            dataType: 'json',
            parse: function(data) {
                var parsed = [];
                for (var i in data) {
                    row = {
                        data: data[i][1]+'|'+data[i][0],
                        value: data[i][0],
                        result: data[i][1]
                    };
                    parsed[parsed.length] = row;
                }
                return parsed;
            },
            formatItem: function(data, i, total) {
                return data.split('|')[0];
            },
        });

The problem I ran into was an assumption in the code of autocomplete
that the items being compared are always strings. With JSON, some of
my values were integers instead, and toLowerCase would die and not
update.

The symptom, oddly enough, only happens when I'd add characters to the
box to refine a search, but not on the initial search. So if I typed
in 'ash', I'd get the matches just fine, but adding a 'c', for 'ashc',
triggered the error: no update would occur, and firebug would catch
's.toLowerCase is not a function' on line 442 of
jquery.autocomplete.js.

The fix is to force a conversion to a string, 's = s.toString()', just
before line 442. Then the plugin seems to work properly.

Reply via email to