In my app I have a hidden checkbox field which I intend to mark checked depending on some condition at runtime.
I have tried various ways to hide the checkbox:
In forms.py using:
'checkbox_field': forms.HiddenInput()
Or in the template:
Using {{ checkbox_field.as_hidden }}
And the checkbox_field is not displayed as expected.
However the problem I am facing is that the checkbox's status ('1' for True) is not saved on form submit. Whereas if I do not hide the checkbox the value is saved.
As a work around (on the other hand), if I keep the checkbox visible, mark it True and then set it as hidden (at runtime), the value is saved.
It's obvious I am getting something wrong here.
My question is:
How may I keep the checkbox hidden and at the same time be able to save its status in the database?