0

Is there any way I can implement the feature like bootstrap-select with data-live-search="true" with the help of wtforms in flask. I want to add a live search in my selectfield so that i can search through the dynamic choices.

Code for bootstrap-select with live search:

<select class="selectpicker" data-live-search="true">
  <option>Mustard</option>
  <option>Ketchup</option>
  <option>Relish</option>
</select>

My python views.py:

@app.route("/r/<int:id>", methods=["POST", "GET"])
def formwtf(id):
    user = Products.query.get(id)
    form = UserDetails(obj=user)
    form.group_id.choices = [(g.category_id, g.category_name) for g in Category.query.order_by('category_name')]

    return render_template('formwtf.html', form=form)

form.py:

class UserDetails(Form):
    group_id = SelectField(u'Group', coerce=int)

my html code:

{% extends "bootstrap/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% block content %}
<div>
{{ form.group_id(class="form-control", data_live_search="true") }}
</div>
{% endblock %}

Is there any way I can use bootstrap-select with wtforms selectfield and add live search in above example. If we cannot use bootstrap-select with wtform is there any other way I can do live search using wtforms.

https://developer.snapappointments.com/bootstrap-select/examples/ You can refer this link to see the demonstration of bootstrap-select with live search.

4

0 回答 0