Ticket #5843: newforms_form_clean.diff

File newforms_form_clean.diff, 1.4 KB (added by Thomas Guettler (Home), 17 years ago)

fixed typos

  • docs/newforms.txt

     
    15571557``_errors`` dictionary attribute on the form as well. In this way, you will
    15581558already know which fields have passed their individual validation requirements.
    15591559
    1560 A simple example
    1561 ~~~~~~~~~~~~~~~~
     1560A simple example: Field.clean()
     1561~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    15621562
    15631563Here's a simple example of a custom field that validates its input is a string
    15641564containing comma-separated e-mail addresses, with at least one address. We'll
     
    15871587        senders = MultiEmailField()
    15881588        cc_myself = forms.BooleanField(required=False)
    15891589
     1590A simple example: Form.clean()
     1591~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     1592
     1593You want to validate, that both passwords are equal. The error is a non
     1594field error (see above)::
     1595
     1596    class UserRegistration(Form):
     1597       username = CharField(max_length=10)
     1598       password1 = CharField(widget=PasswordInput)
     1599       password2 = CharField(widget=PasswordInput)
     1600       def clean(self):
     1601           if self.cleaned_data.get('password1') and self.cleaned_data.get('password2') and self.cleaned_data['password1'] != self.cleaned_data['password2']:
     1602               raise ValidationError(u'Please make sure your passwords match.')
     1603           return self.cleaned_data
     1604
     1605
    15901606Widgets
    15911607=======
    15921608
Back to Top