Code

Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#6733 closed (invalid)

Selected not rendered for SelectMultiple when prefix is present

Reported by: AdamG Owned by: kratorius
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 AdamG 6 years ago.
The patch that solves this particular problem (lets the test case not fail).
field_testcase.py (400 bytes) - added by AdamG 6 years ago.
Testcase that fails on current trunk, passes with patch applied.

Download all attachments as: .zip

Change History (8)

Changed 6 years ago by AdamG

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

Changed 6 years ago by AdamG

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

comment:1 Changed 6 years ago by jacob

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

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

  • milestone set to 1.0

comment:3 Changed 6 years ago by kratorius

  • Keywords forms added; newforms removed
  • Owner changed from nobody to kratorius

comment:4 Changed 6 years ago by kratorius

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

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 6 years ago by kratorius

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

comment:6 Changed 3 years ago by jacob

  • milestone 1.0 deleted

Milestone 1.0 deleted

Add Comment

Modify Ticket

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


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

 
Note: See TracTickets for help on using tickets.