How to make a form field not part of the submitted form

I have an extra field in a django form that triggers javascript to change the fields in other forms:

class MyForm(forms.ModelForm):
    my_extra_form_field = forms.ChoiceField()

    class Meta:
        model = MyModel
        fields = ["field1", "field2"]

    field_order = ["field1", "my_extra_form_field", "field2"]

How can I ensure that my_extra_form_field is not included in the submiteed form?

Just add this to your javascript in template:

// jQuery

// Javascript

adding to NixionSparrow's answer:

You may need to add the attribute required as mentioned in the docs here

my_extra_form_field = forms.ChoiceField(required=False)
Back to Top