Opened 16 years ago

Closed 15 years ago

#8720 closed (invalid)

MultipleHiddenInput doesn't give list of elements in clean method

Reported by: stefan+django@… Owned by: nobody
Component: Forms Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When cleaning a MultipleHiddenInput field, the data is a unicode string of a python representation of a list, so like this u'[u'123', u'456']' which makes it kind of hard to validate the data. I think it should be a proper list, if i'm not missing something here.

Change History (6)

comment:1 by Ivan Giuliani, 16 years ago

milestone: 1.0
Resolution: worksforme
Status: newclosed

I cannot reproduce the error. If you think this is a bug in django, could you please provide a test case or an example?

comment:2 by kyjv, 15 years ago

Resolution: worksforme
Status: closedreopened

Ok, I set up a test project with recent django(r8955).
It has a simple view that renders a form with four hidden inout fields with the name testfield.
When submitted, the values will be sent back to the view and form.is_valid is called. The form looks like this:

from django import forms

class TestForm(forms.Form):
    testfield = forms.CharField(required=False, widget=forms.MultipleHiddenInput())

    def clean_testfield(self):
        print self.cleaned_data.get('testfield')
        print self.cleaned_data.get('testfield')[0]
        return self.cleaned_data.get('testfield')

This will print [u'1', u'2', u'3', u'4'] and the character [

I expected it to give me u'1' when I access it as a list (like a list of unicode characters should behave)

If I'm just doing something wrong, please tell me.

comment:3 by Malcolm Tredinnick, 15 years ago

milestone: 1.0

Too late for 1.0 now.

comment:4 by kyjv, 15 years ago

Well, that depends if you consider that a bug or not. Parsing that string doesn't make sense to me at all.
But anyway, it should just be fixed at some point.

comment:5 by Ivan Giuliani, 15 years ago

I've gone a bit further with this. The problem is that a CharField can't handle multiple fields, and will always evaluate those to a string representation (due to a smart_unicode conversion). I guess in this case you just need to use MultipleChoiceField or a custom field.

I'm not sure whether this should be fixed or not, as my point of view is that if you're using multiple stuff, CharField is not the field for you but I'm leaving this open so someone else could look at this.

comment:6 by Jacob, 15 years ago

Resolution: invalid
Status: reopenedclosed

Yeah, you can't just arbitrarily use any widget with any field and accept it to work. You want a MultipleChoiceField if you're using any sort of multiple widget.

Note: See TracTickets for help on using tickets.
Back to Top