#24010: Unable to use choice values instead of choice keys in form/field
validation
-------------------------------------+-------------------------------------
Reporter: karolyi | Owner: nobody
Type: New feature | Status: new
Component: Forms | Version: 1.7
Severity: Normal | Resolution:
Keywords: field choices error | Triage Stage:
display | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by karolyi):
Oh yes, I forgot that it's a special case, so let me elaborate. I created
a form, where not all of the original choices are available for a field:
{{{
class MyForm(model.ModelForm):
def __init__(self, choices, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.fields['option'].choices = [
x for x in choices.ALL_CHOICES if x[0] in choices]
}}}
Now, when cleaning the form, the option field can get an option which has
a choice, but is not in the 'enabled' choice list. In that case, it'd be
nice to see the corresponding value of choices.ALL_CHOICES.
Does that make sense?
Replying to [comment:7 timgraham]:
> If the value appears in `choices`, isn't it a valid choice? If you could
submit a test or some code to better demonstrate the problem that would be
helpful.
--
Ticket URL: <https://code.djangoproject.com/ticket/24010#comment:8>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.a225f06fb6372ca7858b5b786ece0135%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.