14

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.

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

I also thought about it and I found Django-parsley: https://github.com/agiliq/Django-parsley. It uses parsleyjs which is one the best js libraries for form validation.

I looked at it and I'm still not satisfied since it doesn't give enough flexibility in the client side. At the end of the day I think I will be WET (write everything twice) so I'll have flexibility and I could do exactly what I want in the client side.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.