Opened 4 years ago

Last modified 4 years ago

#31820 closed Bug

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

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 (last modified by Remy)

# 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 (1)

comment:1 by Remy, 4 years ago

Description: modified (diff)
Note: See TracTickets for help on using tickets.
Back to Top