It's heavily based on [wiki:AJAXWidgetComboBox], but i've modified it to make it work with YUI autocomplete widget. == Requirements == * [http://developer.yahoo.com/yui/] - used for AJAX and widget implementation. * [http://www.json.org/json.js] - simplejson, json library == Installation == * Install Yahoo! UI in media/js == Example Use == I'll use the same models that in [wiki:AJAXWidgetComboBox], except that we use "query=" instead of "q=" in search, so you can refer it. The urls.py looks exactly tike this last, but in view.py we have this: {{{ #!python ... from django.utils import simplejson ... def json_lookup(request, queryset, field, limit=5, login_required=False): if login_required and not request.user.is_authenticated(): return redirect_to_login(request.path) obj_list = [] lookup = { '%s__icontains' % field: request.GET['query'],} for obj in queryset.filter(**lookup)[:limit]: obj_list.append({"id": obj.id, "name": getattr(obj, field)}) object = {"ResultSet": { "total": str(limit), "Result": obj_list } } return HttpResponse(simplejson.dumps(object), mimetype='application/javascript') }}} === Template === In template we must put the javascript. I've done it in header section with a event to fire it. So you can put the following code in your content, or in your header if you fire it with an event: {{{
}}} It's all!. You can customize [http://developer.yahoo.com/yui/docs/autocomplete/YAHOO.widget.AutoComplete.html AutoComp] and [http://developer.yahoo.com/yui/docs/autocomplete/YAHOO.widget.DataSource.html DataSource] all you need with [http://developer.yahoo.com/yui/docs/autocomplete/ extra params].