Opened 17 years ago

Closed 17 years ago

#5665 closed (worksforme)

Form instances with MultipleChoiceField share choices

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

Description

If I create two instances of a form with a MultipleChoiceField, and then change the choices on one of them, the choices are also changed on the other :

In [2]: import django.newforms as forms

In [3]: class MyForm(forms.Form):
   ...:     x = forms.MultipleChoiceField()
   ...:     
   ...:     

In [4]: f = MyForm()

In [5]: f2 = MyForm()

In [6]: f2.as_p()
Out[6]: u'<p><label for="id_x">X:</label> <select multiple="multiple" name="x" id="id_x">\n</select></p>'

In [7]: f.fields['x'].choices = [('1','1')]

In [8]: f2.as_p()
Out[8]: u'<p><label for="id_x">X:</label> <select multiple="multiple" name="x" id="id_x">\n<option value="1">1</option>\n</select></p>'

Surely changing the choices in f should not affect f2 ?

Change History (2)

comment:1 by Malcolm Tredinnick, 17 years ago

I don't have time to test it right at the moment, but I'm pretty sure this will have been fixed with the deepcopy() additions to newforms on trunk. If somebody could verify that (try to repeat the problem with trunk), that would be great.

comment:2 by Matt McClanahan, 17 years ago

Resolution: worksforme
Status: newclosed

Verified, fixed in trunk.

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