zircon
zircon

Reputation: 910

how to make multiselecte dropdown field in flask?

I am trying to make a multiselecte dropdown field with clear button in flask like this.

enter image description here

I have tried this but not working the way I want

type = SelectMultipleField("Type",choices=[("None", "None"), ("one", "one"), ("two", "two"), ("three", "three")], default=[('None', 'None')]

but I am getting like this, getting all choices at once without dropdown option

enter image description here

Upvotes: 0

Views: 73

Answers (2)

astroboy
astroboy

Reputation: 68

I also faced the same issue once, Better send the list of choices in your templete and run loop in option tag like this

<option value="None" selected>None</option>
{% for row in vin %}
<option value="{{row}}">{{row}}</option>
{% endfor %}

Upvotes: 1

Tobin
Tobin

Reputation: 2149

The problem in your code comes from the way you have defined the choices. The SelectMultipleField field requires the choices to be defined as a list of tuples. Like this :

typess = SelectMultipleField("Type", choices=[("None", "None"), ("one", "one"), ("two", "two"), ("three", "three")], default=[('None', 'None')])

Upvotes: 0

Related Questions