Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#32434 closed Bug (wontfix)

Using a RadioSelect widget with ModelChoiceField results in no empty option

Reported by: Matthew Rowbottom Owned by: nobody
Component: Forms Version: 3.1
Severity: Normal Keywords: modelchoicefield radioselect
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

Prior to Django v3.1, both of the fields in the following form would be rendered with an empty option, labelled as '---------':

from django import forms
from .models import Animal

class AnimalForm(forms.Form):
    animal_select = forms.ModelChoiceField(
        queryset=Animal.objects.all(),
        required=False,
    )
    animal_radio = forms.ModelChoiceField(
        queryset=Animal.objects.all(),
        required=False,
        widget=forms.RadioSelect()
    )

Since Django v3.1, the field using the RadioSelect widget no longer displays the empty option.

I've tested it with the following versions:

3.0 works
3.0.12 works
3.1 broken
3.1.6 broken
3.2a1 broken

I can't find anything in the docs or the v3.1 release notes (https://docs.djangoproject.com/en/dev/releases/3.1/#forms) to explain the change.

Attachments (1)

Screen Shot 2021-02-06 at 2.25.47 pm.png (89.2 KB ) - added by Matthew Rowbottom 4 years ago.
Example of how the fileds are rendered

Download all attachments as: .zip

Change History (3)

by Matthew Rowbottom, 4 years ago

Example of how the fileds are rendered

comment:1 by Mariusz Felisiak, 4 years ago

Resolution: invalid
Status: newclosed

An empty option for RadioSelect() without blank=True in Django < 3.1 was a bug (see #26813 and da79ee472d803963dc3ea81ee67767dc06068aac). That's why release notes are not included. You can add blank=True to restore an empty option.

comment:2 by Mariusz Felisiak, 4 years ago

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