CheckboxSelectMultipleField problem

5 views
Skip to first unread message

Guillermo Fernandez Castellanos

unread,
Sep 4, 2006, 1:48:38 PM9/4/06
to django...@googlegroups.com
Hi,

I read in the documentation that CheckboxSelectMultipleField has an
identical interface to SelectMultipleField. But this does not seem to
work for me.

I define a Manipulator with SelectMultiple field:
forms.SelectMultipleField(field_name="groups", choices=(('My Test
1','My Test 1'),('My Test 2','My Test 2')))
and in my view i access the information provided by my form:
if request.POST:
new_data = request.POST.copy()
manipulator.do_html2python(new_data)
errors = manipulator.get_validation_errors(new_data)
if not errors:
new_data.getlist('groups')

This works just perfect. I obtain a list with all my choices.

But if I use this instead:
forms.CheckboxSelectMultipleField(field_name="groups", choices=(('My
Test 1','My Test 1'),('My Test 2','My Test 2')))

then I do not obtain anything when I do my new_data.getlist('groups').

What am I doing wrong?
Did I misunderstood the documentation?

Thanks,

G

Guillermo Fernandez Castellanos

unread,
Sep 5, 2006, 2:21:09 PM9/5/06
to django...@googlegroups.com
Cheers,

After a lot of trial-and-error and some source reading, an answer to
my own post:
In order to use a CheckboxSelectMultipleField as a SelectMultipleField
you must prepare the data before :-)

That means:


if request.POST:
new_data = request.POST.copy()

errors = manipulator.get_validation_errors(new_data)
if not errors:

# ADD THIS LINE
manipulator.prepare(new_data)
manipulator.do_html2python(new_data)
new_data.getlist('groups')

Hope it helps other people.

G

On 9/4/06, Guillermo Fernandez Castellanos

mthorley

unread,
Sep 5, 2006, 2:45:16 PM9/5/06
to Django users
I've run into a similar problem witha a custom field I am developing
that is, in-part, based off of CheckboxSelectMultipleField. Do you know
if there is any way to automate the call of prepare?

--
mthorley

Guillermo Fernandez Castellanos

unread,
Sep 5, 2006, 3:06:43 PM9/5/06
to django...@googlegroups.com
Hi,

The prepare is actually a method of Manipulator that calls the prepare
method in each of the fields.

So you might want to call it from the Manipulator.save() method. Or in
the html2python by overiding it, calling first self.prepare() and then
Method.html2Python(self). But I'm just guessing, and it depend of what
you want to do.

Hope it helps,

Guille

mthorley

unread,
Sep 6, 2006, 12:45:54 PM9/6/06
to Django users
Thanks Guille, that looks like it will do what I want, but I just
realized I have another, different, problem.

--
mthorley

Reply all
Reply to author
Forward
0 new messages