Skip to content

Commit

Permalink
Changed checked to a boolean attribute (#1156)
Browse files Browse the repository at this point in the history
As per the HTML spec the checked attribute is a boolean
https://html.spec.whatwg.org/multipage/input.html#attr-input-checked
  • Loading branch information
smithdc1 committed May 11, 2021
1 parent 5c318af commit 79714a6
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{% for choice in field.field.choices %}
<label class="checkbox{% if inline_class %} {{ inline_class }}{% endif %}" for="id_{{ field.html_name }}_{{ forloop.counter0 }}">
<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 }}
<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 }}
</label>
{% endfor %}

Expand Down
2 changes: 1 addition & 1 deletion crispy_forms/templates/bootstrap/layout/radioselect.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

{% for choice in field.field.choices %}
<label for="id_{{ field.html_name }}_{{ forloop.counter0 }}" class="radio{% if inline_class %} {{ inline_class }}{% endif %}">
<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 }}
<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 }}
</label>
{% endfor %}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

{% if not inline_class %}<div class="checkbox">{% endif %}
<label class="{% if inline_class %}checkbox-{{ inline_class }}{% endif %}" for="id_{{ field.html_name }}_{{ forloop.counter0 }}">
<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 }}
<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 }}
</label>
{% if not inline_class %}</div>{% endif %}
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion crispy_forms/templates/bootstrap3/layout/radioselect.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{% for choice in field.field.choices %}
{% if not inline_class %}<div class="radio">{% endif %}
<label for="id_{{ field.html_name }}_{{ forloop.counter0 }}" class="{% if inline_class %}radio-{{ inline_class }}{% endif %}">
<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 }}
<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 }}
</label>
{% if not inline_class %}</div>{% endif %}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% for choice in field.field.choices %}
<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 %}">
<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 }}>
<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 }}>
<label class="{%if use_custom_control%}custom-control-label{% else %}form-check-label{% endif %}" for="id_{{ field.html_name }}_{{ forloop.counter0 }}">
{{ choice.1|unlocalize }}
</label>
Expand Down
2 changes: 1 addition & 1 deletion crispy_forms/templates/bootstrap4/layout/radioselect.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{% for choice in field.field.choices %}
<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 %}">
<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 }}>
<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 }}>
<label for="id_{{ field.html_name }}_{{ forloop.counter0 }}" class="{%if use_custom_control%}custom-control-label{% else %}form-check-label{% endif %}">
{{ choice.1|unlocalize }}
</label>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="form-group" id="div_id_checkboxes"><label class=" requiredField" for="">Checkboxes<span
class="asteriskField">*</span></label>
<div>
<div class="form-check"><input checked="checked" class="form-check-input" id="id_checkboxes_0" name="checkboxes"
<div class="form-check"><input checked class="form-check-input" id="id_checkboxes_0" name="checkboxes"
type="checkbox" value="1"><label class="form-check-label" for="id_checkboxes_0">Option one</label>
</div>
<div class="form-check"><input class="form-check-input" id="id_checkboxes_1" name="checkboxes"
Expand All @@ -19,21 +19,21 @@
<div class="form-check form-check-inline"><input class="form-check-input" id="id_alphacheckboxes_0"
name="alphacheckboxes" type="checkbox" value="option_one"><label class="form-check-label"
for="id_alphacheckboxes_0">Option one</label></div>
<div class="form-check form-check-inline"><input checked="checked" class="form-check-input" id="id_alphacheckboxes_1"
<div class="form-check form-check-inline"><input checked class="form-check-input" id="id_alphacheckboxes_1"
name="alphacheckboxes" type="checkbox" value="option_two"><label class="form-check-label"
for="id_alphacheckboxes_1">Option two</label></div>
<div class="form-check form-check-inline"><input checked="checked" class="form-check-input" id="id_alphacheckboxes_2"
<div class="form-check form-check-inline"><input checked class="form-check-input" id="id_alphacheckboxes_2"
name="alphacheckboxes" type="checkbox" value="option_three"><label class="form-check-label"
for="id_alphacheckboxes_2">Option three</label></div>
</div>
</div>
<div class="form-group" id="div_id_numeric_multiple_checkboxes"><label class=" requiredField" for="">Numeric multiple
checkboxes<span class="asteriskField">*</span></label>
<div>
<div class="form-check"><input checked="checked" class="form-check-input" id="id_numeric_multiple_checkboxes_0"
<div class="form-check"><input checked class="form-check-input" id="id_numeric_multiple_checkboxes_0"
name="numeric_multiple_checkboxes" type="checkbox" value="1"><label class="form-check-label"
for="id_numeric_multiple_checkboxes_0">Option one</label></div>
<div class="form-check"><input checked="checked" class="form-check-input" id="id_numeric_multiple_checkboxes_1"
<div class="form-check"><input checked class="form-check-input" id="id_numeric_multiple_checkboxes_1"
name="numeric_multiple_checkboxes" type="checkbox" value="2"><label class="form-check-label"
for="id_numeric_multiple_checkboxes_1">Option two</label></div>
<div class="form-check"><input class="form-check-input" id="id_numeric_multiple_checkboxes_2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="form-group" id="div_id_checkboxes"><label class=" requiredField" for="">Checkboxes<span
class="asteriskField">*</span></label>
<div>
<div class="custom-checkbox custom-control"><input checked="checked" class="custom-control-input" id="id_checkboxes_0"
<div class="custom-checkbox custom-control"><input checked class="custom-control-input" id="id_checkboxes_0"
name="checkboxes" type="checkbox" value="1"><label class="custom-control-label"
for="id_checkboxes_0">Option one</label></div>
<div class="custom-checkbox custom-control"><input class="custom-control-input" id="id_checkboxes_1"
Expand All @@ -19,11 +19,11 @@
<div class="custom-checkbox custom-control custom-control-inline"><input class="custom-control-input"
id="id_alphacheckboxes_0" name="alphacheckboxes" type="checkbox" value="option_one"><label
class="custom-control-label" for="id_alphacheckboxes_0">Option one</label></div>
<div class="custom-checkbox custom-control custom-control-inline"><input checked="checked"
<div class="custom-checkbox custom-control custom-control-inline"><input checked
class="custom-control-input" id="id_alphacheckboxes_1" name="alphacheckboxes" type="checkbox"
value="option_two"><label class="custom-control-label" for="id_alphacheckboxes_1">Option two</label>
</div>
<div class="custom-checkbox custom-control custom-control-inline"><input checked="checked"
<div class="custom-checkbox custom-control custom-control-inline"><input checked
class="custom-control-input" id="id_alphacheckboxes_2" name="alphacheckboxes" type="checkbox"
value="option_three"><label class="custom-control-label" for="id_alphacheckboxes_2">Option
three</label></div>
Expand All @@ -32,11 +32,11 @@
<div class="form-group" id="div_id_numeric_multiple_checkboxes"><label class=" requiredField" for="">Numeric multiple
checkboxes<span class="asteriskField">*</span></label>
<div>
<div class="custom-checkbox custom-control"><input checked="checked" class="custom-control-input"
<div class="custom-checkbox custom-control"><input checked class="custom-control-input"
id="id_numeric_multiple_checkboxes_0" name="numeric_multiple_checkboxes" type="checkbox"
value="1"><label class="custom-control-label" for="id_numeric_multiple_checkboxes_0">Option
one</label></div>
<div class="custom-checkbox custom-control"><input checked="checked" class="custom-control-input"
<div class="custom-checkbox custom-control"><input checked class="custom-control-input"
id="id_numeric_multiple_checkboxes_1" name="numeric_multiple_checkboxes" type="checkbox"
value="2"><label class="custom-control-label" for="id_numeric_multiple_checkboxes_1">Option
two</label></div>
Expand Down
2 changes: 1 addition & 1 deletion crispy_forms/tests/test_layout_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ def test_multiplecheckboxes(self, settings):
test_form = CheckboxesSampleForm()
html = render_crispy_form(test_form)

assert html.count('checked="checked"') == 6
assert html.count("checked") == 6

test_form.helper = FormHelper(test_form)
test_form.helper[1].wrap(InlineCheckboxes, inline=True)
Expand Down
2 changes: 1 addition & 1 deletion docs/crispy_tag_forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ This is exactly the html that you would get::
<div id="div_id_like_website" class="ctrlHolder">
<label for="id_like_website" class="requiredField">¿Do you like this website?<span class="asteriskField">*</span></label>
<ul>
<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>
<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>
<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>
</ul>
</div>
Expand Down

0 comments on commit 79714a6

Please sign in to comment.