Opened 4 years ago

Last modified 4 years ago

#31820 closed Bug

CheckboxSelectMultiple widget doesn't work with TextChoices enabled CharFields — at Initial Version

Reported by: Remy Owned by: nobody
Component: Forms Version: 3.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

# forms.py

class MovieForm(forms.ModelForm):

    class Meta:
        model = Movie
        fields = [
            'genres',
        ]
        widgets = {
            'genres': forms.CheckboxSelectMultiple
        }

# models.py

class Movie(models.Model):
    class Genre(models.TextChoices):
        SCIFI = 'S', 'Science Fiction'
        ACTION = 'A', 'Action'

    genres = models.charField(max_length=1, choices=Genre.choices)

# template

{{ form.genres.errors }}

Select one checkbox for example, then post the form. On form.save(), the following error is returned to the template:

"Select a valid choice. ['S'] is not one of the available choices."

Change History (0)

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