A python module that allows you to use uni-form with WTForms to give you great looking, optionally client-side verified forms very fast.
The wtfuniform module extends many of the wtforms classes with the needed functionality. Since it imports all the wtforms names and has the same structure, you can use it the same way by changing the import.
# note that the only difference from normal wtforms usage is importing
# from a different module!
from wtfuniform import TextField, PasswordField, SubmitField, Form, validators
class LoginForm(Form):
username = TextField('Your username', [validators.Required()])
password = PasswordField('Your password', [validators.Required()])
login = SubmitField('Login')
# optional, see below: render the form
from wtfuniform.helper import render_form
render_form(LoginForm())To properly work with uni-form, many of the WTForms widgets are extended with extra functionality:
- Widgets have the proper CSS classes (such as
textInputfor text input fields). - CSS classes for client-side validation are added, uni-form will validate accordingly.
BlockLabelsWidgetis a widget that functions almost like aListWidget, but omits the labels. It is used in conjunction withRadioLabeledInputandCheckboxLabeledInputto produce the proper multi checkbox/radio inputs used in uni-form.- All of the above is easily accessible by the
CheckMultipleFieldfor checkboxes. The defaultRadioFieldis already overriden to use these new widgets. - All of the validators are extended with javascript functionality and will perform the same check client-side first, alerting the user of his mistake before he clicked submit.
- There is a helper module
wtfuniform.helperthat includes two functions for HTML code generation:render_fieldandrender_form. For an example on how to use these with jinja2, see formtest.html and simpletest.py.
There are some extensions to the code that are not mandated by uni-form. These included:
DateFieldandDateTimeFieldhave extra css classes ofdateInputanddateTimeInput. This makes it easy to attach date selectors using javascript, e.g. by using jQuery.