From 8fcb55d6e2afbc9fe302b103ecdf91243404b00f Mon Sep 17 00:00:00 2001 From: Marc Brinkmann Date: Sat, 15 Feb 2014 11:45:51 +0100 Subject: [PATCH] Added FormField example to sample application. --- sample_application/__init__.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sample_application/__init__.py b/sample_application/__init__.py index 541c6872..ca033a2f 100644 --- a/sample_application/__init__.py +++ b/sample_application/__init__.py @@ -3,10 +3,17 @@ from flask_appconfig import AppConfig from flask_wtf import Form, RecaptchaField from wtforms import TextField, HiddenField, ValidationError, RadioField,\ - BooleanField, SubmitField + BooleanField, SubmitField, IntegerField, FormField, validators from wtforms.validators import Required +# straight from the wtforms docs: +class TelephoneForm(Form): + country_code = IntegerField('Country Code', [validators.required()]) + area_code = IntegerField('Area Code/Exchange', [validators.required()]) + number = TextField('Number') + + class ExampleForm(Form): field1 = TextField('First Field', description='This is field one.') field2 = TextField('Second Field', description='This is field two.', @@ -21,6 +28,13 @@ class ExampleForm(Form): ]) checkbox_field = BooleanField('This is a checkbox', description='Checkboxes can be tricky.') + + # subforms + mobile_phone = FormField(TelephoneForm) + + # you can change the label as well + office_phone = FormField(TelephoneForm, label='Your office phone') + submit_button = SubmitField('Submit Form') def validate_hidden_field(form, field):