Uroš Trstenjak
Uroš Trstenjak

Reputation: 903

Inline formset does not work only when the field is hidden in template

I'm using inline formset and I can't submit the form when one of the fields is hidden in template.

{{ form.provider.as_hidden }}

When the field is shown in the forms of the formset everything works normally. The field is properly populated and I can submit the form.

{{ form.provider }}

Any ideas what causes this issue?

forms.py

class DurationForm(forms.ModelForm):
    class Meta:
        model = Duration
        fields = [
            'provider',
            'duration',
            'price'
        ]
        widgets={
            "duration":forms.TextInput(attrs={'placeholder':'Duration'}),
            "price":forms.TextInput(attrs={'placeholder':'Price'}),
            #"provider":forms.HiddenInput(),
        }

Upvotes: 2

Views: 452

Answers (1)

YPCrumble
YPCrumble

Reputation: 28692

Per the docs, as_hidden is only for bound fields and should be primarily used internally. You should try using a a HiddenInput widget (or a MultipleHiddenInput widget if that's more appropriate for your provider field) and your form should work fine.

Upvotes: 1

Related Questions