Note that there are some explanatory texts on larger screens.

plurals
  1. POMultipleChoiceField with SelectMultiple widget "Value [...] not a valid choice."
    text
    copied!<p>I have a field defined in my model-</p> <pre><code> languages = models.CharField(max_length = 30, choices=LANGUAGE_CHOICES, blank = True, null = True) </code></pre> <p>The choices are simple-</p> <pre><code>LANGUAGE_CHOICES = ( ('English', 'English'), ) </code></pre> <p>I define a ModelForm on this model and override the field-</p> <pre><code>languages = forms.MultipleChoiceField(choices=LANGUAGE_CHOICES, widget=forms.SelectMultiple) </code></pre> <p>When I fill out the form, select "English", and try to submit, I get an error-</p> <p>languages<br> Value u"[u'English']" is not a valid choice</p> <p>Is there something basic that I am doing wrong? Or is the MultipleChoiceField combined with the SelectMultiple widget not the way to go?</p> <p>Also, is there any reason why the choices tuple can't have the same value twice, like I have it now ('English', 'English')?</p> <p><strong>Here is some additional code that might be useful in getting to the bottom of this</strong></p> <p>Template Code: </p> <pre><code>&lt;div class="abovepad"&gt; &lt;label for="id_languages"&gt;Languages:&lt;/label&gt; {{form.languages}} &lt;/div&gt; </code></pre> <p>The portion of POST data with the languages:</p> <pre><code>u'languages': [u'English'], </code></pre> <p>Relevant snippet of ModelForm code:</p> <pre><code>class ProfileForm(forms.ModelForm): languages = forms.MultipleChoiceField(choices=LANGUAGE_CHOICES) class Meta: model = Student </code></pre> <p>As you see, I barely customized anything. In the past when I ran into this issue I would switch to making the items in the list to models and then using ManyToMany fields which did not cause the same issue. For those instances, having the items be models made sense; in this case it doesn't. I just want to know whether I'm doing something wrong or whether this combo is not supposed to work. If there's no real answer then my other option would be to try and dig through the Django form code to see why its doing what its doing.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload