Search code examples
pythonflaskinputtagsflask-wtforms

flask wtforms , multiple tags in input Filed from QuerySelectField from DB


i have a simple form created with flask wtforms, in this form a have an input field that must contains a multiple tags from tables tags in my databases, this tables is not linked to any other table in my database. this is the model:

class Tag(db.Model):
__tablename__ = 'tags'
id = db.Column(db.Integer, primary_key=True)
tag_name = db.Column(db.String(50))
tag_description = db.Column(db.String(100))
tag_color = db.Column(db.String(10))

forms.py :

def get_tags_name():
      return Tag.query

tags = QuerySelectField('TAGS :', query_factory =  get_tags_name, get_label = "tag_name",allow_blank = True, render_kw={"multiple": "multiple"})

this input give me a multichoses selectfieled, i need to have a multiple tags input. example in image:

enter image description here

Thank you


Solution

  • The solution was to use JqueryUI TokenFieled, this is the implementation.

    https://sliptree.github.io/bootstrap-tokenfield/