AutoComboboxWidget vs AutoComboboxSelectWidget

44 views
Skip to first unread message

Amritha

unread,
Oct 15, 2018, 2:19:23 PM10/15/18
to django-selectable
I need a field which should be both a dropdown field and a text field. I should be able to enter new values (or) choose something from the dropdown.

I was expecting "name" to be a dropdown field with all the values from the lookup.  But only when I start entering something into the field do the list of values appear. Should I be using a AutoComboboxWidget or AutoComboboxSelectWidget or something else to make this work? 


My code is pasted below.

template file
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/themes/base/jquery-ui.css" type="text/css"> <link href="{% static 'css/dj.selectable.css' %}" type="text/css" media="all" rel="stylesheet"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.js"></script> <script type="text/javascript" src="{% static 'js/jquery.dj.selectable.js' %}"></script> <div class="hero-unit"> <div class="container"> <br><br> <form class="form-signin span8" id="fruitform" method="post" enctype="multipart/form-data"> {% csrf_token %} {{ fruitform }} <br /> <script type="text/javascript"> function newParameters(query) { query.foo = 'a'; } $(document).ready(function() { $('#id_name').djselectable('option', 'prepareQuery', newParameters); }); </script> </form> </div> </div>
views.py
def fruit(request): if request.method == 'POST': fruitform = FruitForm(request.POST) else: if request.GET: fruitform = FruitForm(initial=request.GET) else: fruitform = FruitForm() return render(request,'fruit.html', {'fruitform': fruitform})

Lookups.py
class FruitLookup(ModelLookup): model = Fruit search_fields = ('name__icontains', ) registry.register(FruitLookup)

forms.py
class FruitForm(forms.Form): name = AutoCompleteSelectField(lookup_class=FruitLookup,label='Fruit',required=False,widget=AutoComboboxSelectWidget)
class Meta(object): model = Fruit widgets = {'name': selectable.AutoComboboxSelectWidget(lookup_class=FruitLookup), } def __init__(self, *args, **kwargs): super(FruitForm, self).__init__(*args, **kwargs)
Reply all
Reply to author
Forward
0 new messages