Code

Opened 9 months ago

Closed 9 months ago

#20833 closed Bug (invalid)

If there are choices more than 10 when using CheckboxSelectMultiple or SelectMultiple, different options from the original become selected.

Reported by: Naoya Niwa <mine@…> Owned by: nobody
Component: Forms Version: 1.4
Severity: Normal 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

MultipleChoiceField is stored in the database the data in serialized array like "[u'4', u'13']" . However, because the widget does not deserialize when reading it, the results shown is incorrect.

In version 1.4.5, the problem occurs in the 568 line and 548 line of "django/forms/widgets.py".

If one digit, for example, "[u'9']" is converted to "set([u"'", u'9', u', u?', u'u'])" by "set([force_unicode(v) for v in value])", there is no problem in the process to match one by one index number.However, in the case of multi-digit numbers, and thus, for example, "[u'13']" is converted to "set([u"'", u'1', u'3', u', u?', u'u'])", 1 and 3 in the zero-based index is selected.

Attachments (0)

Change History (3)

comment:1 Changed 9 months ago by timo

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

What database field are you using that stores data as a serialized array? It seems to me like to problem may be with that field and not with the forms layer.

comment:2 Changed 9 months ago by Naoya Niwa <mine@…>

I forgot to write. I'm using TextField.

comment:3 Changed 9 months ago by timo

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

Consider using a ManyToManyField instead. I don't think this will work with TextField without some hacking.

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.