A python library for generating client side validation functions from WTForms for various validator libraries.
Project description
WTFormsValidator
A python library for generating client side validation functions from WTForms for various validator libraries.
Developed and tested with Python 3.8 and WTForms 2.3.1 Compatible with Python 3.6 and Python 3.7
Table of Contents
Supported validators
Here you can see which libraries are currently supported or planned to be added, and which WTForms validators are supported by them.
Validators marked with an R are supported via regexes. Using multiple regex-backed validators concurrently will disable all but the last one.
| WTForms validator | YairEO | ParsleyJS | Bouncer.js | just-validate | Pristine | jQuery validation |
|---|---|---|---|---|---|---|
| DataRequired | ✔️ | ✔️ | ✔️ | TODO | TODO | TODO |
| ✔️|R¹ | ✔️|R¹ | ✔️|R¹ | ||||
| EqualTo | ✔️ | ✔️ | ❌ | |||
| InputRequired | ✔️² | ✔️² | ✔️² | |||
| IPAddress | R | R | R | |||
| Length | ✔️ | ✔️ | ✔️ | |||
| MacAddress | R | R | R | |||
| NumberRange | ✔️ | ✔️ | ✔️ | |||
| Optional | ✔️³ | ✔️ | ✔️ | |||
| Regexp | ✔️ | ✔️ | ✔️ | |||
| URL | ✔️|R¹ | ✔️|R¹ | ✔️|R¹ | |||
| UUID | R | R | R | |||
| AnyOf | R | R | R | |||
| NoneOf | R | R | R | |||
| Custom validators | ❌ | ❌ | ❌ | |||
| Custom errors | ❌⁴ | ✔️ | ✔️ |
¹ These libraries have built-in support for e-mail and URL validation, but you can choose to use the WTFormsValidation's regex validators instead. Defaults to built-in, unless that requires WTFormsValidation to change the field's type (in the case of YairEO and Bouncer.js)
² Same behaviour as DataRequired
³ Due to a bug in YairEO, only fields marked as required are validated, so currently this should have no effect
⁴ With YairEO currently you can only override the default messages
Setup
Install it with pip, in your preferred virtual environment:
pip install WTFormsValidation
Running the sample application
- Create a virtualenv
virtualenv -p python3.8 venv - Activate it
. venv/bin/activate - Install the sample's requirements
pip install -r sample/requirements.txt - Run
python -m sample.sample_app - Use the navbar to select which validator's demo you wish to examine.
Usage
Adding the validator library's boilerplate code should be done according to their documentation. Integrate WTFormsValidator as described below.
Integrating with YairEO
Using the default settings for the tagger class:
from WTFormsValidation import yairify
...
render_template('your_template.html', form=yairify(form))
or by instantiating the tagger class yourself:
from WTFormsValidation.tagging.yaireo import YairEOtagger
yaireo_tagger = YairEOtagger(email_builtin=True, url_builtin=True) # defaults negated
...
render_template('your_template.html', form=yaireo_tagger.extend(form))
Integrating with ParsleyJS
Using the default settings for the tagger class:
from WTFormsValidation import parslify
...
render_template('your_template.html', form=parslify(form))
or by instantiating the tagger class yourself:
from WTFormsValidation.tagging.parsley import ParsleyTagger
parsley_tagger = ParsleyTagger(email_builtin=False, url_builtin=False) # defaults negated
...
render_template('your_template.html', form=parsley_tagger.extend(form))
Integrating with Bouncer.js
Using the default settings for the tagger class:
from WTFormsValidation import bouncify
...
render_template('your_template.html', form=bouncify(form))
or by instantiating the tagger class yourself:
from WTFormsValidation.tagging.bouncer import BouncerTagger
bouncer_tagger = BouncerTagger(email_builtin=True, url_builtin=True) # defaults negated
...
render_template('your_template.html', form=bouncer_tagger.extend(form))
Implementing custom behaviour
You can inherit from the default tagger classes (YairEOtagger, ParsleyTagger, BouncerTagger) and override any handler functions to suit your use case.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file WTFormsValidation-0.1.0.tar.gz.
File metadata
- Download URL: WTFormsValidation-0.1.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd5cac1b2e3e0045aa5c60c1ab6d3af048885d8c041dc1484155024dd8500741
|
|
| MD5 |
ca82366c885592debf307822d7245f76
|
|
| BLAKE2b-256 |
7cbd85643434701ac9518f4ac9614d3bccdee2b80766a265cab235e5f3db7252
|
File details
Details for the file WTFormsValidation-0.1.0-py3-none-any.whl.
File metadata
- Download URL: WTFormsValidation-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
056e04232555baf0b67ffc7d3bdcb23784a5c310b29f98a9ad7f2229440fd24d
|
|
| MD5 |
bb5f5ab96f3441080861f2162fc6f40f
|
|
| BLAKE2b-256 |
c6fa5fb16a1a9f8cf11c79f2517e5536fd1c8995937603792e1c25996563ecc0
|