javascript - Programmatically select the first suggestion in django-autocomplete-light -


how can select first given option? i'm feeding autocomplete widget data reverse geocoding results (city) basing on user's location. have database cities , need select first suggested option.

autocomplete_light_registry.py

autocomplete_light.register(     city,     search_fields=('^name',),     autocomplete_js_attributes={'placeholder': _('start typing...')} ) 

forms.py

class customerform(forms.modelform):     city = forms.modelchoicefield(city.objects.all(), label=_('city'), widget=autocomplete_light.choicewidget('cityautocomplete')) 

locations.js

$('#id_city_text').val(ymaps.geolocation.city); var autocomplete = $('#id_city_text').yourlabsautocomplete(); autocomplete.refresh(); 

thanks help.

screenshots:

references:

here's how auto select first choice if there one:

        $(document).ready(function() {             var autocomplete = $('#id_city_text').yourlabsautocomplete();             autocomplete.show = function(html) {                 yourlabs.autocomplete.prototype.show.call(this, html)                 var choices = this.box.find(this.choiceselector);                  if (choices.length == 1) {                     this.input.trigger('selectchoice', [choices, this]);                 }             }         }); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -