newforms: message "this field is required" although required=False

3 views
Skip to first unread message

patrickk

unread,
Sep 7, 2007, 10:53:00 AM9/7/07
to Django users
I´m creating a dynamic newform and when going to the page, I´m getting
an error-message "This Field is required", although required ist set
to False when building the Form.

Here´s part of the code:

field_list = []
date = forms.ChoiceField(label='Wann', required=False,
choices=date_choices_list, widget=forms.Select(attrs={'class':
'vSelectField'}))
field_list.append(('Datum', date))
...
form = CinemaFormDynamic(field_list=field_list)


class CinemaFormDynamic(forms.Form):
def __init__(self, data=None, auto_id=False, field_list=[]):
forms.Form.__init__(self, data, auto_id)
for field in field_list:
self.fields[field[0]] = field[1]


thanks,
patrick

patrickk

unread,
Sep 7, 2007, 11:42:32 AM9/7/07
to Django users
just printed "form.is_bound" in my view: the result is "True",
although I didn´t invoke the Form with any data.

btw: I´m using the current SVN-version and did an update last week
(before the update it worked).

any help with this?

thanks,
patrick

olivier

unread,
Sep 7, 2007, 7:31:53 PM9/7/07
to Django users
Hi,

> widget=forms.Select(attrs={'class': 'vSelectField'}))

This let me think you use a javascript validator. Are you sure the
message comes from the server ?
You should try form.is_valid() or whatever.


> just printed "form.is_bound" in my view: the result is "True",
> although I didn´t invoke the Form with any data.

Yes, you bound it with 'data', even if it is None.
You may want to do stuff like :
if data is None:
forms.Form.__init(self, auto_id = auto_id)
else:
forms.Form.__init(self, data, auto_id)

But I'm not sure anyway that forms.Form.__init__(self, ...) is the
right way to do it.


Regards,

Olivier

patrickk

unread,
Sep 8, 2007, 4:52:11 AM9/8/07
to Django users

On Sep 8, 1:31 am, olivier <oliviermig...@gmail.com> wrote:
> Hi,
>
> > widget=forms.Select(attrs={'class': 'vSelectField'}))
>
> This let me think you use a javascript validator. Are you sure the
> message comes from the server ?
> You should try form.is_valid() or whatever.

no javascript. form.is_valid() is not the issue, because I didn´t send
anything.

>
> > just printed "form.is_bound" in my view: the result is "True",
> > although I didn´t invoke the Form with any data.
>
> Yes, you bound it with 'data', even if it is None.
> You may want to do stuff like :
> if data is None:
> forms.Form.__init(self, auto_id = auto_id)
> else:
> forms.Form.__init(self, data, auto_id)
>
> But I'm not sure anyway that forms.Form.__init__(self, ...) is the
> right way to do it.

got the script from on of the django-devs.

thanks,
patrick

>
> Regards,
>
> Olivier

Reply all
Reply to author
Forward
0 new messages