Support for jQuery UI autocomplete

Issue #12 resolved
Mitar Milutinovic
created an issue

jQuery libraries used for autocompletion have become obsolete by new jQuery UI support for autocompletion.

I am attaching my own autocomplete implementation which uses just jQuery UI. I have dropped support for other libraries. And I have added some more logic to the view to allow hardcoded choices (and not only querysets). The idea is that I can give some hardcoded initial choices combined with a queryset of all values given by users until now.

I made {{{autocomplete_widget_factory}}} function which transforms any widget to one with autocompletion. For example



class AutocompleteCityField(geo_fields.CityField): def formfield(self, kwargs): kwargs['widget'] = widgets.autocomplete_widget_factory(super(AutocompleteCityField, self).formfield(kwargs).widget.class)('cities') return super(AutocompleteCityField, self).formfield(**kwargs) }}}

This could also be wrapped into a factory for fields. ;-)

I also added features as explained in <<issue 10>> and <<issue 9>>.

It can be the initialized like:



We autocomplete with cities from a hard-coded list and all

cities entered until now by users

autocomplete_view.register( name = 'cities', choices = geo_fields.CITIES, queryset = models.UserProfile.objects.values('city').distinct().order_by('city'), fields = ('city',), value = 'city', limit = 10, case_sensitive = False, ) }}}

Feel free to integrate it into your Django application.

Comments (4)

  1. Log in to comment