Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13951

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

$
0
0

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'


Viewing all articles
Browse latest Browse all 13951

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>