Login

AgreementField

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

  1. codigo alto nivel by MrRocklion 1 month ago
  2. Load template from specific app by Krzysiek555 1 month, 3 weeks ago
  3. PostgreSQL JSON subqueries by dolamroth 1 month, 3 weeks ago
  4. "Magic Link" Management Command by webology 7 months ago
  5. Closest ORM models to a latitude/longitude point by simonw 7 months ago

Comments

chrisrbennett (on August 13, 2008):

This snippet is deprecated because the landing of newforms fixes the boolean checkbox issue.

#

Please login first before commenting.