Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Javascript form validation

I'd like to add js validation to my forms, and that validation should be done without requests to my server.

So, say, I open a page with form, make some errors and js code show me (without single request to the server) that, say, this field is required, this field is too short, this field should be a number etc.

The main idea - DRY - this js code should be auto-generated and/or it should get validation rules from form.

Now I would implement such validation by writing custom js code (or use some form validation libraries), and I need to duplicate validation rules - in forms and in js code. This is not DRY :) Also I'll get some problems connected with error messages.

Is there solution for my need?

Thanks.

like image 817
demalexx Avatar asked Feb 23 '10 14:02

demalexx


1 Answers

I found this post in my bookmarks, but I haven't tried it out myself yet.

http://eikke.com/django-validation-an-introduction/

it's a small post that explains how to generate client side validation javascript from a Newform form (keeping you dry). some code is also available in a git repository

like image 137
Stefan De Boey Avatar answered Oct 05 '22 12:10

Stefan De Boey