Opened 7 years ago

Closed 7 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: UI/UX:


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 ?

Attachments (0)

Change History (2)

comment:1 Changed 7 years ago by mtredinnick

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 Changed 7 years ago by mattmcc

  • Resolution set to worksforme
  • Status changed from new to closed

Verified, fixed in trunk.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.