views:

91

answers:

3

I'm using jQuery validation system for client-side validation. The backend works with django. jQuery use an interesting set of rules in JSON format.

Does exists something to use the same rules on django side or I need to code it myself?

+2  A: 

No, no such thing exists.

Yes, you need to code it yourself.

However, I imagine you could possibly create widgets which are able to deliver generic validation js routines based on the modelFields. Such as "This should be chars not more than max_length". However they could not trivially generate client-side code to validate any custom validation written in python, nor even something like "This must be the username of an existing user". But if you take this trouble to build widgets which do basic validation based on the modelFields please contribute them to open source :-D

John Mee
It is already for an open source project so it will anyway :) Of course this could be valid only for operation that need to be duplicated, for example date validation, or password confirm validation and things like that... If it involve database it will involve the serverside and some ajax for clientside validation.
Andrea Ambu
+2  A: 

This article describes some level of integration: http://streamhacker.com/2010/03/08/jquery-validation-django-forms/

It doesn't look like it actually generates the clientside metadata based on the serverside metadata, but at least puts all rules in one place. May be a good starting point for generating those rules based on the existing Django rules.

Jörn Zaefferer
A: 

I haven't used it myself, but there is the django-ajax-forms project.

Ludwik Trammer