#16308 closed Uncategorized (worksforme)
CheckboxSelectMultiple can not show the data on the view
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Forms | Version: | 1.3 |
Severity: | Normal | Keywords: | Checkbox Select Multiple |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
CheckboxSelectMultiple can not show the data on the view.
when the form use CheckboxSelectMultiple, it can not show the data on view.
problem code :
class CheckboxSelectMultiple(SelectMultiple): def render(self, name, value, attrs=None, choices=()): if value is None: value = [] has_id = attrs and 'id' in attrs final_attrs = self.build_attrs(attrs, name=name) output = [u'<ul>'] # Normalize to strings str_values = set([force_unicode(v) for v in value])
solution:
str_values = set([force_unicode(v) for v in '''eval'''(value)])
Attachments (1)
Change History (7)
comment:1 by , 14 years ago
Description: | modified (diff) |
---|---|
Resolution: | → needsinfo |
Status: | new → closed |
by , 14 years ago
Attachment: | multipleselect.zip added |
---|
comment:2 by , 14 years ago
I have upload a clear example to show this problem.
The example can be download by the attachment
comment:3 by , 14 years ago
Resolution: | needsinfo |
---|---|
Status: | closed → reopened |
Reopening so that this ticket can be reviewed again (I don't have time to do it just now).
comment:4 by , 14 years ago
Component: | Documentation → Forms |
---|---|
Resolution: | → worksforme |
Status: | reopened → closed |
I had a look at your attached code and as I can see you missing the initial option.
You can use initial to select values on a choice field like this:
gender = forms.MultipleChoiceField(initial=['m'],required=False, widget=CheckboxSelectMultiple, choices=(('m', 'Male'), ('f', 'Female')))
this generates in the view:
u'<p>Gender: <ul>\n<li><label><input checked="checked" type="checkbox" name="gender" value="m" /> Male</label></li>\n<li><label><input type="checkbox" name="gender" value="f" /> Female</label></li>\n</ul></p>'
hope this helps!
comment:5 by , 14 years ago
I think you did not catch what i meen.
When you submit your form, the release version can not keep the selected option.
If the choice is (('m', 'Male'), ('f', 'Female')), the realse version will work.
If the choices is (('male', 'Male'), ('female', 'Female')), the realse version will not work.
I've reformatted your description -- next time please use preview to make sure your code samples display correctly.
Using
eval()
is potentially dangerous as maliciously code could get executed. It is unclear what problem you're having. Please reopen this ticket if you can provide a clear example or a test case illustrating the problem that you're trying to solve.