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