Skip to content

Home

About

Django Front End Validators allows you to reuse server-side model field validators to perform front end form validation in JavaScript.

For more information, see How It Works.

Quickstart

Install Django Front End Validators

pip install django-front-end-validators

Update INSTALLED_APPS

INSTALLED_APPS = (
    ...
    'front_end_validators',
    ...
)

Configure settings

# The directory into which Transcrypt transpiles JS
STATICFILES_DIRS = [
    # Transcrypt 3.7:
    'your_project/__target__'
    # Transcrypt 3.6:
    'your_project/__javascript__',
]

# The path to your validators.py file
VALIDATORS_FILE = os.path.join(BASE_DIR, 'your_project/validators.py')

Add template tag

{% load front_end_validators %}<!doctype html>
<html>
  <head>
    {{ form.media.css }}
  </head>
<body>
  {% block content %}{% endblock %}
  {% front_end_validators_js %}
  {{ form.media.js }}
</body>
</html>

Transpile validators

./manage.py transpile_validators

Write forms

from front_end_validators.forms import FrontEndValidatorsModelForm
from .models import YourModel


class YourModelForm(FrontEndValidatorsModelForm):
    class Meta:
        model = YourModel
        fields = '__all__'

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox