[Django] #29273: MultipleChoiceField auto selects on initial load the empty value

28 views
Skip to first unread message

Django

unread,
Mar 29, 2018, 8:41:43 AM3/29/18
to django-...@googlegroups.com
#29273: MultipleChoiceField auto selects on initial load the empty value
--------------------------------------------+------------------------
Reporter: Tim Kleinschmidt | Owner: nobody
Type: Uncategorized | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
hi,

I upgraded Django from 1.8 to 1.11, in the last month and we have now a
bug that the empty choice is always selected on initial page load and
leads to confusion. If I deselect and select the value it work like
intended.

It seems for me that there is no
[https://github.com/django/django/blob/1.11.11/django/forms/widgets.py#L591
check] if something was already selected or if it be a fresh form. Like it
was in
[https://github.com/django/django/blob/1.8.19/django/forms/widgets.py#L523
1.8] in `selected_choices`

I think this report also apply to the `ModelMultipleChoiceField`

e.g.
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
choices = [(u'', '(no extra)'), (u'cheese', u'Cheese'), (u'Pepper',
u'Pepper')]
extra_topics = forms.MultipleChoiceField(required=False,
choices=choices)
}}}
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29273>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 29, 2018, 9:25:40 AM3/29/18
to django-...@googlegroups.com
#29273: MultipleChoiceField auto selects on initial load the empty value
----------------------------------+--------------------------------------

Reporter: Tim Kleinschmidt | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Tim Kleinschmidt):

* type: Uncategorized => Bug


--
Ticket URL: <https://code.djangoproject.com/ticket/29273#comment:1>

Django

unread,
Mar 29, 2018, 12:28:11 PM3/29/18
to django-...@googlegroups.com
#29273: MultipleChoiceField auto selects on initial load the empty value
----------------------------------+--------------------------------------

Reporter: Tim Kleinschmidt | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------

Comment (by Tim Graham):

Can you please be more explicit about the steps to reproduce the issue?

--
Ticket URL: <https://code.djangoproject.com/ticket/29273#comment:2>

Django

unread,
Mar 29, 2018, 4:55:05 PM3/29/18
to django-...@googlegroups.com
#29273: MultipleChoiceField incorrectly selects the empty value for an empty form
----------------------------------+------------------------------------

Reporter: Tim Kleinschmidt | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.11
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Tim Graham):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

The difference can be seen here:
{{{
from django import forms
choices = [('', '(no extra)'), ('cheese', 'Cheese'), ('Pepper', 'Pepper')]
class Form(forms.Form):
extra_topics = forms.MultipleChoiceField(required=False,
choices=choices)

form = Form()
print(form)
}}}
The first option renders as `<option value="" selected>(no
extra)</option>` in Django 1.11+ but without `selected` in older versions.

--
Ticket URL: <https://code.djangoproject.com/ticket/29273#comment:3>

Django

unread,
Mar 30, 2018, 4:37:23 AM3/30/18
to django-...@googlegroups.com
#29273: MultipleChoiceField incorrectly selects the empty value for an empty form
----------------------------------+------------------------------------
Reporter: Tim Kleinschmidt | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.11

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by Claude Paroz):

Not surprisingly, this can be bisected to the template-based widget
rendering commit [b52c73008a9d67e9ddbb].

--
Ticket URL: <https://code.djangoproject.com/ticket/29273#comment:4>

Django

unread,
Mar 30, 2018, 6:41:55 AM3/30/18
to django-...@googlegroups.com
#29273: MultipleChoiceField incorrectly selects the empty value for an empty form
----------------------------------+------------------------------------
Reporter: Tim Kleinschmidt | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 1.11

Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Claude Paroz):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9838 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29273#comment:5>

Django

unread,
Apr 2, 2018, 9:34:35 AM4/2/18
to django-...@googlegroups.com
#29273: MultipleChoiceField incorrectly selects the empty value for an empty form
----------------------------------+------------------------------------
Reporter: Tim Kleinschmidt | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.11
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"f3b69f9757ec03057441ebbd52b7cdbfed31fb32" f3b69f97]:
{{{
#!CommitTicketReference repository=""
revision="f3b69f9757ec03057441ebbd52b7cdbfed31fb32"
Fixed #29273 -- Prevented initial selection of empty choice in multiple
choice widgets.

Regression in b52c73008a9d67e9ddbb841872dc15cdd3d6ee01.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29273#comment:6>

Django

unread,
Apr 2, 2018, 9:34:53 AM4/2/18
to django-...@googlegroups.com
#29273: MultipleChoiceField incorrectly selects the empty value for an empty form
----------------------------------+------------------------------------
Reporter: Tim Kleinschmidt | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.11

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"160829d35b54a97977bf8ce5588aa19b1cfc2b43" 160829d3]:
{{{
#!CommitTicketReference repository=""
revision="160829d35b54a97977bf8ce5588aa19b1cfc2b43"
[2.0.x] Fixed #29273 -- Prevented initial selection of empty choice in
multiple choice widgets.

Regression in b52c73008a9d67e9ddbb841872dc15cdd3d6ee01.

Backport of f3b69f9757ec03057441ebbd52b7cdbfed31fb32 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29273#comment:7>

Django

unread,
Apr 2, 2018, 9:35:08 AM4/2/18
to django-...@googlegroups.com
#29273: MultipleChoiceField incorrectly selects the empty value for an empty form
----------------------------------+------------------------------------
Reporter: Tim Kleinschmidt | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.11

Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"b25433a225d85c6dace5d5e97f4553c01f035fb1" b25433a]:
{{{
#!CommitTicketReference repository=""
revision="b25433a225d85c6dace5d5e97f4553c01f035fb1"
[1.11.x] Fixed #29273 -- Prevented initial selection of empty choice in
multiple choice widgets.

Regression in b52c73008a9d67e9ddbb841872dc15cdd3d6ee01.

Backport of f3b69f9757ec03057441ebbd52b7cdbfed31fb32 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29273#comment:8>

Reply all
Reply to author
Forward
0 new messages