我有一个带有选择字段的简单表单:
class seguimentTutorialForm(forms.Form):
pregunta_select = forms.ChoiceField( )
def __init__(self, *args, **kwargs):
self.pregunta = kwargs.pop('pregunta', None)
super(seguimentTutorialForm,self).__init__(*args,**kwargs)
self.fields['pregunta_select'].widget.choices=
[('',u'---Tria---')] +
[ (x.strip(),x.strip(), ) for x
in self.pregunta.possibles_respostes.split('|')]
我在 POST 数据上收到此验证错误:
Select a Valid Choice NO is not one of the available choices
这是生成的 html 表单:
<tr>
<td class="label_tag">
<label for="id_6_3-pregunta_select">blah blah?</label>:</td>
<td class="tria_tag" class="conte_errors" >
<select name="6_3-pregunta_select" id="id_6_3-pregunta_select">
<option value="">---Tria---</option>
<option value="NO" selected="selected">NO</option>
<option value="Sí, AO">Sí, AO</option>
<option value="Sí, AA">Sí, AA</option>
<option value="Sí, PS">Sí, PS</option>
<option value="Sí, UEE">Sí, UEE</option>
</select>
<br/><span class="help_text">( Tipus alumne )</span>
<ul class="errorlist"><li>Select a Valid Choice NO is not one of the available choices.</li></ul>
</td>
</tr>
解决这个问题的一些想法?