On Nov 9, 12:34 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> On Fri, 2007-11-09 at 06:26 +0000, Milan Andric wrote:
>
> > On Nov 9, 12:02 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
> > wrote:
> > > > Shouldn't the form give errors and not validate?
>
> > > Nope. It's a bit tricky, though. The problem is that HTML forms do not
> > > send *anything* for a checkbox that you don't check. So missing data for
> > > a checkbox field means it wasn't checked and is, therefore, False.
>
> > Seems if I have (pseudocode)
>
> > Form:
> >    f = someField(required=True)
>
> > When I pass no data into that form it should not validate?  Just
> > doesn't seem right?
>
> In general, that will be true. However checkboxes are special: no data
> just means the value wasn't checked in the form, it doesn't mean that
> form field wasn't processed. It's an HTML oddity that Django has to
> accomodate.
>
> However, now that I'm thinking about this, there might be a bug here.
> Having required=True should mean you're required to check the box. There
> was a huge debate about this in a ticket, but the general acceptance
> amongst the maintainers and frequent contributors who commented was that
> that was the correct behaviour.
>
> I was responsible for checking in the change that makes no data = False
> for checkboxes (only), but I think I might have broken something in the
> process. I'll have to look a bit deeper into this at some point.
>
> Malcolm

Ok, so I have a  forms.BooleanField(required=True) ... that is pretty
much meaningless because when an html form is submitted the checkbox
is only present in the POST if it is checked.

So I handle it manually in the view by setting the dict value to
False.  This still doesn't do anything because now a value has been
submitted so required=True conditional passes.

None of this makes sense to me at least:

In [35]: class testForm(forms.Form):
   ....:     checkme=forms.BooleanField(required=True)
   ....:
   ....:

In [36]: f=testForm({})

In [37]: f.is_valid()
Out[37]: True

In [38]: f=testForm({'checkme':False})

In [39]: f.is_valid()
Out[39]: True

In [40]: f=testForm({'checkme':''})

In [41]: f.is_valid()
Out[41]: False

--
Milan
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to