Introspection tells me that django fields have a “hidden_widget” attribute. Maybe its not this attribute’s given purpose, but its mere existence tempts me to use it in a template to conditionally render a hidden widget.
e.g.,
{% if some condition %}
{{ form.my_field }}
{% else %}
{{ form.my_field.hidden_widget }}
{% endif %}
But this doesn’t work. Is it possible to use the hidden widget this way? What am I missing?
I realize I could do this by dynamically setting the widget in the init of my custom Form class based on some custom kwarg for the conditional, which I pass in to it, but the above solution (dynamically rendering the hidden widget in the template) would be way simpler, if its available.
I was close, but using the wrong function. The answer, for those who are interested, is: