Opened 14 years ago

Closed 14 years ago

Last modified 14 years ago

#16308 closed Uncategorized (worksforme)

CheckboxSelectMultiple can not show the data on the view

Reported by: jekyllhy3@… 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 Julien Phalip)

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)

multipleselect.zip (16.6 KB ) - added by jekyllhy3@… 14 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Julien Phalip, 14 years ago

Description: modified (diff)
Resolution: needsinfo
Status: newclosed

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.

by jekyllhy3@…, 14 years ago

Attachment: multipleselect.zip added

comment:2 by anonymous, 14 years ago

I have upload a clear example to show this problem.
The example can be download by the attachment

comment:3 by Julien Phalip, 14 years ago

Resolution: needsinfo
Status: closedreopened

Reopening so that this ticket can be reviewed again (I don't have time to do it just now).

comment:4 by Bernhard Essl, 14 years ago

Component: DocumentationForms
Resolution: worksforme
Status: reopenedclosed

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 anonymous, 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.

comment:6 by anonymous, 14 years ago

Please submit the form, you will see the problem.

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