Package: wtforms-html5
WTForms HTML5VERSION:0.6.1WTForms HTML5generates render keywords for HTML5 INPUT widgets used by theWTFormslibrary.EvolutionOriginal Function: This module used to add support for the new HTML5 INPUT
elements toWTForms. Besides supporting the new INPUTtypes, it also set
some of the newattributesautomatically, based on widget type and what kind
of validators where set for the field.Changes:WTForms— beginning around version 1.0.4 — started to implement
some of these features. As of late 2016 the development version — that
should become version 3 — has enough support for them IMO, so that to prevent
the duplication of functionality,WTForms HTML5dropped all the fields,
widgets and validators — just use vanillaWTForms.Current Function: starting with0.2versions ofWTForms HTML5merely
contain one function:get_html5_kwargs— it adds the automatically generated
keys to therender keywordsof aWTFormsfield. A slim subclass of the new
defaultMetaclass for forms is also provided:AutoAttrMeta. If you use this
class as your formsMeta, you get the automatic attributes for all fields in
your form, just like in the original version ofWTForms HTML5.Supported Auto–AttributesrequiredIs set if the field has therequiredflag set. This happens i.e. if you use
theDataRequiredorInputRequiredvalidator. Therequiredattribute is
used by browsers to indicate a required field (and most browsers won't
activate the forms action unless all required fields have content).invalidIf the field got any validation errors, the CSS classinvalidis added. Theinvalidclass is also set by browsers, if they detect errors on a field.
The validation errors detected by your code, are then by default styled in
the same way as browser generated errors.min/maxandminlength/maxlengthIf eitherLengthorNumberRangeis used as a validator to set minimal
and / or maximal values, the corresponding INPUT attribute is
set (based on which validator is used). This allows for browser based
validation of the values.titleIf notitleis provided for a field, thedescription(if one is set) is
used for thetitleattribute.ExampleDeclare your form just like in vanillaWTForms, but includeAutoAttrMetaas your meta class:>>>fromwtformsimportForm,StringField>>>fromwtforms.validatorsimportInputRequired,Length>>>fromwtforms_html5importAutoAttrMeta>>>classMyForm(Form):...classMeta(AutoAttrMeta):...pass...test_field=StringField(...'Testfield',...validators=[InputRequired(),Length(min=3,max=12)],...description='Just a test field.',...)>>>form=MyForm()The only difference is, that you include aMetaclass, that inherits fromAutoAttrMeta.This meta class sets the above mentioned attributes automatically for all the
fields of the form:>>>form.test_field()'<input id="test_field" maxlength="12" minlength="3" name="test_field" required title="Just a test field." type="text" value="">'Theminlengthandmaxlengthattributes are created because theLengthvalidator was used. And the field is markedrequiredbecause of theInputRequiredvalidator. The field also gets atitletaken from the fieldsdescription.If you validate the form and any errors pop up, the field also getinvalidadded to its class:>>>form.validate()False>>>form.test_field()'<input class="invalid" id="test_field" maxlength="12" minlength="3" name="test_field" required title="Just a test field." type="text" value="">'InstallYou can installWTForms HTML5withpipor fromsource.pipis"a tool for installing and managing Python packages". If you don't
have it installed, see thepip install instructions.pipinstall--userwtforms-html5Install RequirementsSinceWTForms HTML5only adds functionality toWTForms, you need to
have it installed too. But if you use the installation method described
above, it should have been taken care of.Testing and ContributionWTForms HTML5is at home at:https://github.com/brutus/wtforms-html5/You can runmake setupafter checkout, to setup a development environment.If you find any bugs, issues or anything, please use theissue tracker.TestingYou can run the provideddoctestlike this:make doctest. If you want to
run thetest cases, runmake unittest(ormake coverage). You can also
runmake all-teststo run this for all supported versions (this might take
some time though).If something fails, please get in touch.