this has two drawbacks: 1) the URL is validated in the "wrong" place (in clean() instead of clean_url()) 2) the error, if one occurs, is not assigned to the errors['url'] but errors['__all__']
fixing 2) would also be hackish imho wolfram On Nov 23, 2007 2:28 PM, Matthias Kestenholz <[EMAIL PROTECTED]> wrote: > > Hi Wolfram, > > > On Fri, 2007-11-23 at 14:05 +0100, Wolfram Kriesing wrote: > > I got an alike problem, I ran through the docs, mailing lists, etc. > > but no solution. > > > > I got: > > > > class LinkForm(forms.Form): > > TYPE_CHOICES = ( > > ('user', _('User link')), > > ('url', _('Web link')), > > ) > > type = forms.ChoiceField(choices=TYPE_CHOICES) > > user = forms.IntegerField(required=False) > > url = forms.URLField(required=False, initial='http://') > > > > I want to validate the url-field _only_ when the type-field is set to > > "url" otherwise I don't, and I also don't want to get errors thrown > > otherwise! > > But since the Field's clean() method is called first the URL always > > gets validated :-( > > So I have no chance to modify the url-Field to an empty string using > > the various clean-methods. > > > > Is overriding the __init__() and putting the logic in there my only chance? > > Or did I miss something here? > > I'd create an CharField instead of an URLField and call the validation > functions in django.core.validators inside the Form.clean() method. That > way you can reuse the validation without any hackery on your part. > > > Matthias > > > -- > http://spinlock.ch/blog/ > > > > > -- cu Wolfram --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@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-users?hl=en -~----------~----~----~----~------~----~------~--~---