顯示具有 WTForms 標籤的文章。 顯示所有文章
顯示具有 WTForms 標籤的文章。 顯示所有文章

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) 

2015年6月19日 星期五

Flask WTForms example

References :
Reusing Flask-WTF forms. » BTHLabs
The Flask Mega-Tutorial, Part III: Web Forms - miguelgrinberg.com

WTForms dynamic set default SelectField value

myform = TestForm()
myform.select.default = 2
myform.process() // <-- :="" br="" missed="" this="" you="">
myform.title.data = 'xxxx'
....




References :
Change default value of a SelectField after form creation · Issue #106 · wtforms/wtforms

WTForms print validate error

print form.errors

WTForms Dynamic Select Field 'Not a Valid Choice' error

area = SelectField(coerce=int)




References :
python - Not a Valid Choice for Dynamic Select Field WTFORMS - Stack Overflow

WTForms get label text

{{ form.my_field.label.text }}




References :
accessing label property without html generation.. - Google Groups