How can I select the first given option? I'm feeding the autocomplete widget with the data from reverse geocoding results (city) basing on user's location. I have a database with cities and I need to select the 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 for your help.
Screenshots:
- http://cl.ly/image/2V0I373e2C0M (achieved)
- http://cl.ly/image/3S2p382o2N12 (goal)
References: