2015年12月20日 星期日

wtforms multiple checkboxes

Example 1:
from wtforms import widgets, SelectMultipleField 
data = [('value_a','Value A'), ('value_b','Value B'), ('value_c','Value C')]
class ExampleForm(Form):
    example = SelectMultipleField('Pick Things!', choices=data, option_widget=widgets.CheckboxInput(), widget=widgets.ListWidget(prefix_label=False) )
@app.route('/')
def home():
    form = ExampleForm()
    return render_template('index.html', form=form)  

Inherit :
from wtforms import widgets, SelectMultipleField  
class MultiCheckboxField(SelectMultipleField):
    widget = widgets.ListWidget(prefix_label=False)
    option_widget = widgets.CheckboxInput() 
data = [('value_a', 'Value A'), ('value_b', 'Value B'), ('value_c', 'Value C')] 
class PermissionEditForm(Form):
    permissions = MultiCheckboxField('Pick Things!', choices=data) 
@app.route('/')
def home():
    form = ExampleForm()
    return render_template('index.html', form=form) 

沒有留言:

張貼留言