ChoiceFields using the SelectMultiple widget fail validation when optional and the browser doesn't submit a value for it.
Firefox won't submit a value for <select> form fields. Without a value, SelectMultiple sets the value to [].
The clean() function in ChoiceField checks to see if the value is None or an empty string via EMPTY_VALUES, but not [], so it tries to lookup [] in the list of acceptable choices and fails with an invalid_choice message.
from django import newforms as forms
from django.http import QueryDict
class PostForm(forms.Form):
text = forms.CharField()
broken = forms.ChoiceField(widget=forms.SelectMultiple, required=False)
# Firefox won't submit a <select> form field that has no option selected
postdata = QueryDict('&text=super')
form = PostForm(postdata)
form.is_valid()
form.errors
This will output:
>>> form.is_valid()
False
>>> form.errors
{'broken': [u'Select a valid choice. That choice is not one of the available choices.']}