- Author:
- chrisrbennett
- Posted:
- June 5, 2008
- Language:
- Python
- Version:
- .96
- Score:
- 5 (after 5 ratings)
Creating new field to handle checkbox validation in situations where the checkbox must be checked, as in check to agree to terms and such.
Thanks to Daniel Pope for the suggestion on Django Trac Ticket #5957
1 2 3 4 5 6 7 8 9 | from django.newforms.fields import BooleanField
from django.newforms import ValidationError
class AgreementField(BooleanField):
def clean(self, value):
super(AgreementField, self).clean(value)
if not value:
raise ValidationError("You must agree to continue.")
else:
return value
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
This snippet is deprecated because the landing of newforms fixes the boolean checkbox issue.
#
Please login first before commenting.