bdoubleu
bdoubleu

Reputation: 6107

Django check form field attribute in template

I need to check if a form field is disabled in the template. The field is disabled depending on some other factors but I've simplified it below.

class MyForm(forms.Form):
    quantity = forms.IntegerField()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['quantity'].disabled = True

Then in the template I'd like to do something like this:

{% if form.quantity.disabled is True %}
    ...
{% endif %}

Upvotes: 1

Views: 554

Answers (1)

bdoubleu
bdoubleu

Reputation: 6107

Found the solution through accessing field.field.disabled

Upvotes: 1

Related Questions