I have a BooleanField in a standard Django Form defined as:
my_boolean_field = BooleanField(initial=True)
when I render my form with initial data, and my_boolean_field is set to an initial value of False, when the form renders it is still checked despite the fact that the value is false as the html shows:
<p><label for="id_2">my_boolean_field</label>:
<input checked="checked"
type="checkbox"
name="2"
value="False"
id="id_2" />
</p>
Has anyone else experienced this, or knows how to fix it so that when the initial data/input value is false then the checkbox is not checked?
UPDATE: Even if I remove the initial=True argument from the BooleanField the same thing happens.
Best Answer
Firstly, you can't have
required=False
on aBooleanField
, useNullBooleanField
instead:let me know what the HTML output of the new widget is once you've done this?
EDIT
I assumed that this is a ModelForm. Is this a regular django.forms.Form?
EDIT 2
My test form:
My template:
This is what I get for output when I view page source. EDITED
My View NEW
What you are showing and what I'm seeing aren't matching up. paste your full form, view and template please?
EDIT 3
I only see output like this:
when I put False in quotes: