1

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.

Akash Deshpande
  • 2,583
  • 10
  • 41
  • 82

1 Answers1

10

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

Darwin
  • 1,809
  • 15
  • 17