Opened 16 years ago
Closed 16 years ago
#8720 closed (invalid)
MultipleHiddenInput doesn't give list of elements in clean method
Reported by: | 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 |
Description
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 , 16 years ago
milestone: | → 1.0 |
---|---|
Resolution: | → worksforme |
Status: | new → closed |
comment:2 by , 16 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
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:4 by , 16 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 , 16 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 , 16 years ago
Resolution: | → invalid |
---|---|
Status: | reopened → closed |
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.
I cannot reproduce the error. If you think this is a bug in django, could you please provide a test case or an example?