On 6/13/07, Norman Harman <[EMAIL PROTECTED]> wrote: > > Kind of think CharField should do this, but I can imagine someone not > wanting it. > > class StrippedCharField(forms.CharField): > """ > Newforms CharField that strips trailing and leading spaces > """ > def clean(self, value): > if value is not None: > value = value.strip() > return super(StrippedCharField, self).clean(value)
In case where an automatically stripping charfield is needed it's a quite trivial task to create one. However, adding such model to the Django is probably not useful, since it doesn't bring any value to current form fields. Making the stripping behavior to be the default for CharField would be even worse: Think about password field, which depends heavily on CharField implementation. Now, the user would like to change her password from "foo" to "bar " (note the trailing space). The charfield would trim out the trailing space and make it impossible for the user to log in using the password she thought she changed. > I also hacked this together, comments/improvements welcomed. > > class ChangePasswordForm(forms.Form): > password = forms.CharField(max_length=32, min_length=6, > widget=PasswordInput > confirm = forms.CharField(max_length=32, min_length=6, > widget=PasswordInput > > def clean(self): > print self.cleaned_data['password'], self.cleaned_data['confirm'] > if self.cleaned_data['password'] != self.cleaned_data['confirm']: > raise ValidationError("Passwords do not match.") > return self.cleaned_data Comments for the custom forms created should probably be asked from the Django Users mailing list - Jyrki -- Jyrki // [EMAIL PROTECTED] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers?hl=en -~----------~----~----~----~------~----~------~--~---