Skip to content

Allow blank/null on radio.html choices #2631

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

Merged
merged 2 commits into from
Mar 16, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions rest_framework/templates/rest_framework/horizontal/radio.html
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
{% load i18n %}
{% trans "None" as none_choice %}

<div class="form-group">
{% if field.label %}
<label class="col-sm-2 control-label {% if style.hide_label %}sr-only{% endif %}">{{ field.label }}</label>
{% endif %}
<div class="col-sm-10">
{% if style.inline %}
{% if field.allow_null or field.allow_blank %}
<label class="radio-inline">
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %} />
{{ none_choice }}
</label>
{% endif %}
{% for key, text in field.choices.items %}
<label class="radio-inline">
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %}>
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %} />
{{ text }}
</label>
{% endfor %}
{% else %}
{% if field.allow_null or field.allow_blank %}
<div class="radio">
<label>
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %} />
{{ none_choice }}
</label>
</div>
{% endif %}
{% for key, text in field.choices.items %}
<div class="radio">
<label>
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %}>
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %} />
{{ text }}
</label>
</div>
Expand Down
11 changes: 11 additions & 0 deletions rest_framework/templates/rest_framework/inline/radio.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
{% load i18n %}
{% trans "None" as none_choice %}

<div class="form-group {% if field.errors %}has-error{% endif %}">
{% if field.label %}
<label class="sr-only">{{ field.label }}</label>
{% endif %}
{% if field.allow_null or field.allow_blank %}
<div class="radio">
<label>
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %}>
{{ none_choice }}
</label>
</div>
{% endif %}
{% for key, text in field.choices.items %}
<div class="radio">
<label>
Expand Down
17 changes: 17 additions & 0 deletions rest_framework/templates/rest_framework/vertical/radio.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{% load i18n %}
{% trans "None" as none_choice %}

<div class="form-group {% if field.errors %}has-error{% endif %}">
{% if field.label %}
<label {% if style.hide_label %}class="sr-only"{% endif %}>{{ field.label }}</label>
{% endif %}
{% if style.inline %}
<div>
{% if field.allow_null or field.allow_blank %}
<label class="radio-inline">
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %} />
{{ none_choice }}
</label>
{% endif %}
{% for key, text in field.choices.items %}
<label class="radio-inline">
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %}>
Expand All @@ -12,6 +21,14 @@
{% endfor %}
</div>
{% else %}
{% if field.allow_null or field.allow_blank %}
<div class="radio">
<label>
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %} />
{{ none_choice }}
</label>
</div>
{% endif %}
{% for key, text in field.choices.items %}
<div class="radio">
<label>
Expand Down