Skip to content

Commit 79714a6

Browse files
authored
Changed checked to a boolean attribute (#1156)
As per the HTML spec the checked attribute is a boolean https://html.spec.whatwg.org/multipage/input.html#attr-input-checked
1 parent 5c318af commit 79714a6

File tree

10 files changed

+18
-18
lines changed

10 files changed

+18
-18
lines changed

crispy_forms/templates/bootstrap/layout/checkboxselectmultiple.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{% for choice in field.field.choices %}
88
<label class="checkbox{% if inline_class %} {{ inline_class }}{% endif %}" for="id_{{ field.html_name }}_{{ forloop.counter0 }}">
9-
<input type="checkbox"{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
9+
<input type="checkbox"{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
1010
</label>
1111
{% endfor %}
1212

crispy_forms/templates/bootstrap/layout/radioselect.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
{% for choice in field.field.choices %}
88
<label for="id_{{ field.html_name }}_{{ forloop.counter0 }}" class="radio{% if inline_class %} {{ inline_class }}{% endif %}">
9-
<input type="radio"{% if choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
9+
<input type="radio"{% if choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
1010
</label>
1111
{% endfor %}
1212

crispy_forms/templates/bootstrap3/layout/checkboxselectmultiple.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
{% if not inline_class %}<div class="checkbox">{% endif %}
1010
<label class="{% if inline_class %}checkbox-{{ inline_class }}{% endif %}" for="id_{{ field.html_name }}_{{ forloop.counter0 }}">
11-
<input type="checkbox"{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
11+
<input type="checkbox"{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
1212
</label>
1313
{% if not inline_class %}</div>{% endif %}
1414
{% endfor %}

crispy_forms/templates/bootstrap3/layout/radioselect.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{% for choice in field.field.choices %}
88
{% if not inline_class %}<div class="radio">{% endif %}
99
<label for="id_{{ field.html_name }}_{{ forloop.counter0 }}" class="{% if inline_class %}radio-{{ inline_class }}{% endif %}">
10-
<input type="radio"{% if choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
10+
<input type="radio"{% if choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
1111
</label>
1212
{% if not inline_class %}</div>{% endif %}
1313
{% endfor %}

crispy_forms/templates/bootstrap4/layout/checkboxselectmultiple.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
{% for choice in field.field.choices %}
77
<div class="{%if use_custom_control%}custom-control custom-checkbox{% if inline_class %} custom-control-inline{% endif %}{% else %}form-check{% if inline_class %} form-check-inline{% endif %}{% endif %}">
8-
<input type="checkbox" class="{%if use_custom_control%}custom-control-input{% else %}form-check-input{% endif %}{% if field.errors %} is-invalid{% endif %}"{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>
8+
<input type="checkbox" class="{%if use_custom_control%}custom-control-input{% else %}form-check-input{% endif %}{% if field.errors %} is-invalid{% endif %}"{% if choice.0 in field.value or choice.0|stringformat:"s" in field.value or choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>
99
<label class="{%if use_custom_control%}custom-control-label{% else %}form-check-label{% endif %}" for="id_{{ field.html_name }}_{{ forloop.counter0 }}">
1010
{{ choice.1|unlocalize }}
1111
</label>

crispy_forms/templates/bootstrap4/layout/radioselect.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
{% for choice in field.field.choices %}
77
<div class="{%if use_custom_control%}custom-control custom-radio{% if inline_class %} custom-control-inline{% endif %}{% else %}form-check{% if inline_class %} form-check-inline{% endif %}{% endif %}">
8-
<input type="radio" class="{%if use_custom_control%}custom-control-input{% else %}form-check-input{% endif %}{% if field.errors %} is-invalid{% endif %}"{% if choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked="checked"{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>
8+
<input type="radio" class="{%if use_custom_control%}custom-control-input{% else %}form-check-input{% endif %}{% if field.errors %} is-invalid{% endif %}"{% if choice.0|stringformat:"s" == field.value|default_if_none:""|stringformat:"s" %} checked{% endif %} name="{{ field.html_name }}" id="id_{{ field.html_name }}_{{ forloop.counter0 }}" value="{{ choice.0|unlocalize }}" {% if field.field.disabled %}disabled="true"{% endif %} {{ field.field.widget.attrs|flatatt }}>
99
<label for="id_{{ field.html_name }}_{{ forloop.counter0 }}" class="{%if use_custom_control%}custom-control-label{% else %}form-check-label{% endif %}">
1010
{{ choice.1|unlocalize }}
1111
</label>

crispy_forms/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_false.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="form-group" id="div_id_checkboxes"><label class=" requiredField" for="">Checkboxes<span
33
class="asteriskField">*</span></label>
44
<div>
5-
<div class="form-check"><input checked="checked" class="form-check-input" id="id_checkboxes_0" name="checkboxes"
5+
<div class="form-check"><input checked class="form-check-input" id="id_checkboxes_0" name="checkboxes"
66
type="checkbox" value="1"><label class="form-check-label" for="id_checkboxes_0">Option one</label>
77
</div>
88
<div class="form-check"><input class="form-check-input" id="id_checkboxes_1" name="checkboxes"
@@ -19,21 +19,21 @@
1919
<div class="form-check form-check-inline"><input class="form-check-input" id="id_alphacheckboxes_0"
2020
name="alphacheckboxes" type="checkbox" value="option_one"><label class="form-check-label"
2121
for="id_alphacheckboxes_0">Option one</label></div>
22-
<div class="form-check form-check-inline"><input checked="checked" class="form-check-input" id="id_alphacheckboxes_1"
22+
<div class="form-check form-check-inline"><input checked class="form-check-input" id="id_alphacheckboxes_1"
2323
name="alphacheckboxes" type="checkbox" value="option_two"><label class="form-check-label"
2424
for="id_alphacheckboxes_1">Option two</label></div>
25-
<div class="form-check form-check-inline"><input checked="checked" class="form-check-input" id="id_alphacheckboxes_2"
25+
<div class="form-check form-check-inline"><input checked class="form-check-input" id="id_alphacheckboxes_2"
2626
name="alphacheckboxes" type="checkbox" value="option_three"><label class="form-check-label"
2727
for="id_alphacheckboxes_2">Option three</label></div>
2828
</div>
2929
</div>
3030
<div class="form-group" id="div_id_numeric_multiple_checkboxes"><label class=" requiredField" for="">Numeric multiple
3131
checkboxes<span class="asteriskField">*</span></label>
3232
<div>
33-
<div class="form-check"><input checked="checked" class="form-check-input" id="id_numeric_multiple_checkboxes_0"
33+
<div class="form-check"><input checked class="form-check-input" id="id_numeric_multiple_checkboxes_0"
3434
name="numeric_multiple_checkboxes" type="checkbox" value="1"><label class="form-check-label"
3535
for="id_numeric_multiple_checkboxes_0">Option one</label></div>
36-
<div class="form-check"><input checked="checked" class="form-check-input" id="id_numeric_multiple_checkboxes_1"
36+
<div class="form-check"><input checked class="form-check-input" id="id_numeric_multiple_checkboxes_1"
3737
name="numeric_multiple_checkboxes" type="checkbox" value="2"><label class="form-check-label"
3838
for="id_numeric_multiple_checkboxes_1">Option two</label></div>
3939
<div class="form-check"><input class="form-check-input" id="id_numeric_multiple_checkboxes_2"

crispy_forms/tests/results/bootstrap4/test_layout/test_use_custom_control_is_used_in_checkboxes_true.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="form-group" id="div_id_checkboxes"><label class=" requiredField" for="">Checkboxes<span
33
class="asteriskField">*</span></label>
44
<div>
5-
<div class="custom-checkbox custom-control"><input checked="checked" class="custom-control-input" id="id_checkboxes_0"
5+
<div class="custom-checkbox custom-control"><input checked class="custom-control-input" id="id_checkboxes_0"
66
name="checkboxes" type="checkbox" value="1"><label class="custom-control-label"
77
for="id_checkboxes_0">Option one</label></div>
88
<div class="custom-checkbox custom-control"><input class="custom-control-input" id="id_checkboxes_1"
@@ -19,11 +19,11 @@
1919
<div class="custom-checkbox custom-control custom-control-inline"><input class="custom-control-input"
2020
id="id_alphacheckboxes_0" name="alphacheckboxes" type="checkbox" value="option_one"><label
2121
class="custom-control-label" for="id_alphacheckboxes_0">Option one</label></div>
22-
<div class="custom-checkbox custom-control custom-control-inline"><input checked="checked"
22+
<div class="custom-checkbox custom-control custom-control-inline"><input checked
2323
class="custom-control-input" id="id_alphacheckboxes_1" name="alphacheckboxes" type="checkbox"
2424
value="option_two"><label class="custom-control-label" for="id_alphacheckboxes_1">Option two</label>
2525
</div>
26-
<div class="custom-checkbox custom-control custom-control-inline"><input checked="checked"
26+
<div class="custom-checkbox custom-control custom-control-inline"><input checked
2727
class="custom-control-input" id="id_alphacheckboxes_2" name="alphacheckboxes" type="checkbox"
2828
value="option_three"><label class="custom-control-label" for="id_alphacheckboxes_2">Option
2929
three</label></div>
@@ -32,11 +32,11 @@
3232
<div class="form-group" id="div_id_numeric_multiple_checkboxes"><label class=" requiredField" for="">Numeric multiple
3333
checkboxes<span class="asteriskField">*</span></label>
3434
<div>
35-
<div class="custom-checkbox custom-control"><input checked="checked" class="custom-control-input"
35+
<div class="custom-checkbox custom-control"><input checked class="custom-control-input"
3636
id="id_numeric_multiple_checkboxes_0" name="numeric_multiple_checkboxes" type="checkbox"
3737
value="1"><label class="custom-control-label" for="id_numeric_multiple_checkboxes_0">Option
3838
one</label></div>
39-
<div class="custom-checkbox custom-control"><input checked="checked" class="custom-control-input"
39+
<div class="custom-checkbox custom-control"><input checked class="custom-control-input"
4040
id="id_numeric_multiple_checkboxes_1" name="numeric_multiple_checkboxes" type="checkbox"
4141
value="2"><label class="custom-control-label" for="id_numeric_multiple_checkboxes_1">Option
4242
two</label></div>

crispy_forms/tests/test_layout_objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ def test_multiplecheckboxes(self, settings):
501501
test_form = CheckboxesSampleForm()
502502
html = render_crispy_form(test_form)
503503

504-
assert html.count('checked="checked"') == 6
504+
assert html.count("checked") == 6
505505

506506
test_form.helper = FormHelper(test_form)
507507
test_form.helper[1].wrap(InlineCheckboxes, inline=True)

docs/crispy_tag_forms.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ This is exactly the html that you would get::
9898
<div id="div_id_like_website" class="ctrlHolder">
9999
<label for="id_like_website" class="requiredField">¿Do you like this website?<span class="asteriskField">*</span></label>
100100
<ul>
101-
<li><label for="id_like_website_0"><input checked="checked" name="like_website" value="1" id="id_like_website_0" type="radio" class="radioselect" /> Yes</label></li>
101+
<li><label for="id_like_website_0"><input checked name="like_website" value="1" id="id_like_website_0" type="radio" class="radioselect" /> Yes</label></li>
102102
<li><label for="id_like_website_1"><input value="0" type="radio" class="radioselect" name="like_website" id="id_like_website_1" /> No</label></li>
103103
</ul>
104104
</div>

0 commit comments

Comments
 (0)