this is what i currently have to do :(
if the clean_<field>() function would get all the form-data that would
no be necessary!!
def __init__(self, *args, **kwargs):
data = len(args) and args[0] or kwargs['data']
# Copy the data first, so we can modify them,
copied = dict([(k, v) for k, v in data.items()])
# Empty the url field if the type is not 'url'.
pref = kwargs['prefix']+'-'
if not copied.get(pref+'type', '')=='url':
copied[pref+'url'] = ''
if len(args):
args[0] = copied
else:
kwargs['data'] = copied
forms.Form.__init__(self, *args, **kwargs)
wolfram
On Nov 23, 2007 2:05 PM, Wolfram Kriesing <[EMAIL PROTECTED]> 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?
>
> --
> cu
>
> Wolfram
>
--
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 [email protected]
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
-~----------~----~----~----~------~----~------~--~---