Opened 9 years ago

Closed 8 years ago

Last modified 5 years ago

#6733 closed (invalid)

Selected not rendered for SelectMultiple when prefix is present

Reported by: Adam Gomaa Owned by: Ivan Giuliani
Component: Forms Version: master
Severity: Keywords: forms
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

See the testcase with the problem here. I have attached the diff that fixes the problem for me, but it breaks other widgets (regressiontests.forms.tests.__test__.form_tests fails), and it's not really clear to me how to fix it or really what the root cause is. Either way, hopefully it's a starting point for someone who understands the internals of newforms better than myself...

Attachments (2)

data_prefix_dict.diff (573 bytes) - added by Adam Gomaa 9 years ago.
The patch that solves this particular problem (lets the test case not fail).
field_testcase.py (400 bytes) - added by Adam Gomaa 9 years ago.
Testcase that fails on current trunk, passes with patch applied.

Download all attachments as: .zip

Change History (8)

Changed 9 years ago by Adam Gomaa

Attachment: data_prefix_dict.diff added

The patch that solves this particular problem (lets the test case not fail).

Changed 9 years ago by Adam Gomaa

Attachment: field_testcase.py added

Testcase that fails on current trunk, passes with patch applied.

comment:1 Changed 9 years ago by Jacob

Needs documentation: unset
Needs tests: unset
Patch needs improvement: set
Triage Stage: UnreviewedAccepted

Looks good. A proper patch with the testcase and the fix all in a single diff would be extremely helpful to whoever applies this.

comment:2 Changed 8 years ago by Matt McClanahan

milestone: 1.0

comment:3 Changed 8 years ago by Ivan Giuliani

Keywords: forms added; newforms removed
Owner: changed from nobody to Ivan Giuliani

comment:4 Changed 8 years ago by Ivan Giuliani

Resolution: invalid
Status: newclosed

This ticket is invalid. You need to specify the prefix when passing data to the form. The provided test case (slightly modified version):

CHOICES=[(1, 'one'), (2, 'two')]

class TestForm(forms.Form):
    number = forms.MultipleChoiceField(choices=CHOICES, required=False)

data = { 'number': 1 }
foo = TestForm(data, prefix='mypre')

should be:

CHOICES=[(1, 'one'), (2, 'two')]

class TestForm(forms.Form):
    number = forms.MultipleChoiceField(choices=CHOICES, required=False)

data = { 'mypre-number': 1 }
foo = TestForm(data, prefix='mypre')

comment:5 Changed 8 years ago by Ivan Giuliani

(the attribute's value in data in the examples should be [1], not 1)

comment:6 Changed 5 years ago by Jacob

milestone: 1.0

Milestone 1.0 deleted

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