18👍
You should ALWAYS validate your form on the server side, client side validation is but a convenience for the user only.
That being said, Django forms has a variable form.errors which shows if certain form fields were incorrect.
{{ form.name_of_field.errors }} can give you each individual error of each field that’s incorrectly filled out. See more here:
6👍
There’s a pluggable Django app (django-ajax-forms) that helps validate forms on the client side through JavaScript. But as AlbertoPL says, use client side validation only as a usability measure (e.g. telling a user that his desired username is already taken without reloading the registration page). There are all kind of ways to sidestep client side validation, in most cases as simple as deactivating JavaScript.
Generally speaking: presume all data coming from the outside as faulty until validated.
- Django dependent select
- Django Admin in Angularjs
- Django + mod_wsgi. Set OS environment variable from Apache's SetEnv
- How to build a REST client frontend for a REST API backend?
- Push notifications with django and GCM
4👍
Just came accross django-floppyforms, which seems to do clientside validation by default. They use HTML5 which supports clientside validation by default. Not sure if they also use javascript though if the browser doesn’t support HTML5. Haven’t tried it myself yet.
Link to django-floppyforms: Documentation and Github
- Django: lock particular rows in table
- Creating users in django (NOT NULL constraint failed: auth_user.last_login)
- Django: AttributeError: 'NoneType' object has no attribute 'split'
- Django reversion does not save revisions made in shell
2👍
If you are using bootstrap then you can simply add required attribute in forms field. For example if there is programe field then you can validate it like:
In forms.py:
programme = forms.ChoiceField(course_choices,required=True, widget=forms.Select(attrs={'required':'required'}))
Note: It requires to link to bootstrap files in your .html
page of that form.
- Django admin – how to get all registered models in templatetag?
- Get foreign key objects in a single query
- How to tell if your select query is within a transaction or not?
1👍
You will need to do this is JS. This app integrates forms with parsley.js to tag the forms with correct data-* attributes automatically.