#31820: CheckboxSelectMultiple widget doesn't work with TextChoices enabled
CharFields
------------------------+--------------------------------------
Reporter: Remy | Owner: nobody
Type: Bug | Status: new
Component: Forms | Version: 3.0
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
------------------------+--------------------------------------
Description changed by Remy:
Old 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."
> }}}
New 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."
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/31820#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.ccbd4a57837cbf595b892c7057436a35%40djangoproject.com.