In flask wtf forms MultipleCheckboxField, how to set different attributes to each checkbox choice?

29 Views Asked by At

How to set html attributes to each of the checkbox choices (key and value) (different for each choice)?

My code:

class MultipleCheckboxField(SelectMultipleField):
    widget = ListWidget(prefix_label=False)
    option_widget = CheckboxInput()

class Form(FlaskForm)
    course = MultipleCheckboxField("Courses",choices=[
            (str(c["_id"]), c["course"], {"data-duration": c["duration"]})
            for c in db.Courses.find({})
        ])

Adding {"data-example": 'example-value'} works with SelectMultipleField but doing the same with my custom MultipleCheckboxField, I'm getting an error: TypeError: Field.__init__() got an unexpected keyword argument 'data-duration'

0

There are 0 best solutions below