Validators

keg_elements.forms.form_validator(func=None, only_when_fields_valid=False)

Decorator used to mark a method as a form level validator.

Parameters:

only_when_fields_valid – Use to disable validator if form already has errors.

class keg_elements.forms.validators.NumberScale(scale, message=None)

Ensure the field’s numeric value is within a maximum number of decimal places.

class keg_elements.forms.validators.ValidateAlphaNumeric(message=None)

A validator to make sure than a form field contains only alphanumeric data

Example::

import keg_elements.forms.validators as validators

wtforms.StringField(‘AlphaNumeric’, validators=[validators.ValidateAlphaNumeric()])

class keg_elements.forms.validators.ValidateUnique(object_html_link=None)

Ensure the field’s value is unique from other values

This validator requires a get_object_by_field(field) on the form which returns an object (if one exists) or None to check for uniqueness.

Pass object_html_link to this validator’s __init__ to get an error message which contains a hyperlink to the existing object.

Note

Combine with wtforms.validators.optional when a field is nullable to allow for None values.