Skip to main content

Bug Tracker

Side navigation

#3097 closed enhancement (invalid)

Opened June 27, 2008 10:16PM UTC

Closed October 12, 2009 11:33PM UTC

[autocomplete] pass function as data source

Reported by: khoker Owned by:
Priority: major Milestone: 1.3
Component: plugin Version: 1.2.6
Keywords: autocomplete Cc:
Blocked by: Blocking:
Description

Jorn (and all), great work on the autocomplete plugin. If you are accepting enhancements, I would love to see the ability to pass a function as a datasource. Right now autocomplete accepts data as an array of objects [{obj1},{obj2},{obj3},...] or a URL. (urlOrData). I think it would add useful functionality to be able to pass a function as well. That would make the autocomplete plugin a lot more dynamic with respect to the dataset to be searched. In addition, there's often the need to manage your own ajax calls outside of the jQuery universe, depending on how many active requests an application is trying to manage, so the ajax call might need to be passed to a function instead of manually done at the plugin.

Attachments (1)
  • autocomplete_fn.zip (23.5 KB) - added by mwinckler July 23, 2008 06:01PM UTC.

    Modified jquery.autocomplete.js to accept function as datasource

Change History (2)

Changed July 23, 2008 06:01PM UTC by mwinckler comment:1

I agree. I needed this same capability, so I wrote some modifications to the plugin to do the job. I haven't tested it thoroughly yet, but it seems to be working with the default settings. I've attached a zip archive with my modifications and example usage. I made the changes to Revision: $Id: jquery.autocomplete.js 5747 2008-06-25 18:30:55Z joern.zaefferer $. Lines changed include: 17-21, 333-352 (inserted block), and 424 (after the insert).

You can pass the autocomplete function a function reference instead of a URL or array. The function reference should accept two parameters: the query term, and a callback to execute (this will be the "success" function in the autocompleter). The function then calls the callback, passing it the result set corresponding to the query. The result should by an array of objects, each of which has a 'value' property with the term to be displayed in the autocompleter, e.g.:

[{value:'apple'},{value:'apothecary'}]

The objects could also have other properties for use in formatting, etc.

I just started playing around with the autocomplete plugin, so my code is probably not the best solution, but hopefully it's a starting point.

Changed October 12, 2009 11:33PM UTC by dmethvin comment:2

resolution: → invalid
status: newclosed

This is not a jQuery core bug. Please report plugin bugs to the plugin's author, or ask on the jQuery forums. jQuery UI bugs should be reported on the UI bug tracker, http://dev.jqueryui.com .