Ticket #5843: newforms_form_clean.diff
File newforms_form_clean.diff, 1.4 KB (added by , 17 years ago) |
---|
-
docs/newforms.txt
1557 1557 ``_errors`` dictionary attribute on the form as well. In this way, you will 1558 1558 already know which fields have passed their individual validation requirements. 1559 1559 1560 A simple example 1561 ~~~~~~~~~~~~~~~~ 1560 A simple example: Field.clean() 1561 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1562 1562 1563 1563 Here's a simple example of a custom field that validates its input is a string 1564 1564 containing comma-separated e-mail addresses, with at least one address. We'll … … 1587 1587 senders = MultiEmailField() 1588 1588 cc_myself = forms.BooleanField(required=False) 1589 1589 1590 A simple example: Form.clean() 1591 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1592 1593 You want to validate, that both passwords are equal. The error is a non 1594 field 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 1590 1606 Widgets 1591 1607 ======= 1592 1608