문제

I have a model Foo. I have a modelform FooForm. In FooForm I am adding a dynamic field "too". This is a select field.

 FooForm(modelform)
    too = forms.ChoiceField(widget = forms.Select())
    class Meta:
        model = Foo

In the template I am adding options dynamically to this "too field"

$('.too').append('<option value='timepass'>'+timepass'</option>');

In the view these values are not validating, as there are no choices available to it for comparing. How do I validate and extract this field ? Thanks in advance.

도움이 되었습니까?

해결책

Instead of using a forms.ChoiceField you must use forms.CharField, with widget=forms.Select(), this way you are open to any value and not limited by a choices list in the form

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top