Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add for attribute in label for RadioSelect #699

Merged
merged 4 commits into from Aug 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion crispy_forms/templates/bootstrap/layout/radioselect.html
Expand Up @@ -5,7 +5,7 @@
{% include 'bootstrap/layout/field_errors_block.html' %}

{% for choice in field.field.choices %}
<label class="radio{% if inline_class %} {{ inline_class }}{% endif %}">
<label for="id_{{ field.html_name }}_{{ forloop.counter }}" class="radio{% if inline_class %} {{ inline_class }}{% endif %}">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like this isn't necessary if the input is within the label:

A label element can have both a for attribute and a contained control element, as long as the for attribute points to the contained control element.

for label attribute

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but, in some cases when you need to hide the input to use after and/or before pseudo elements this tweak keeps onclick behaviour.
On the other hand, i'll try it with a contained input.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to merge this then. Don't see any reasons not to.

Can you resolve the conflicts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course! 😀

Thanks!

<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.counter }}" value="{{ choice.0|unlocalize }}" {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
</label>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion crispy_forms/templates/bootstrap3/layout/radioselect.html
Expand Up @@ -6,7 +6,7 @@

{% for choice in field.field.choices %}
{% if not inline_class %}<div class="radio">{% endif %}
<label class="{% if inline_class %}radio-{{ inline_class }}{% endif %}">
<label for="id_{{ field.html_name }}_{{ forloop.counter }}" 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.counter }}" value="{{ choice.0|unlocalize }}" {{ field.field.widget.attrs|flatatt }}>{{ choice.1|unlocalize }}
</label>
{% if not inline_class %}</div>{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion crispy_forms/templates/bootstrap4/layout/radioselect.html
Expand Up @@ -6,7 +6,7 @@

{% for choice in field.field.choices %}
{% if not inline_class %}<div class="radio">{% endif %}
<label class="{% if inline_class %}radio-{{ inline_class }}{% endif %}">
<label for="id_{{ field.html_name }}_{{ forloop.counter }}" 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.counter }}" value="{{ choice.0|unlocalize }}" {{ field.field.widget.attrs|flatatt }}>
{{ choice.1|unlocalize }}
</label>
Expand Down