Skip to content

Commit 992971d

Browse files
committed
Merge pull request #2631 from Ins1ne/feature/issue-2559
Allow blank/null on radio.html choices
2 parents 4cd49d5 + 7159b31 commit 992971d

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

rest_framework/templates/rest_framework/horizontal/radio.html

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
1+
{% load i18n %}
2+
{% trans "None" as none_choice %}
3+
14
<div class="form-group">
25
{% if field.label %}
36
<label class="col-sm-2 control-label {% if style.hide_label %}sr-only{% endif %}">{{ field.label }}</label>
47
{% endif %}
58
<div class="col-sm-10">
69
{% if style.inline %}
10+
{% if field.allow_null or field.allow_blank %}
11+
<label class="radio-inline">
12+
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %} />
13+
{{ none_choice }}
14+
</label>
15+
{% endif %}
716
{% for key, text in field.choices.items %}
817
<label class="radio-inline">
9-
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %}>
18+
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %} />
1019
{{ text }}
1120
</label>
1221
{% endfor %}
1322
{% else %}
23+
{% if field.allow_null or field.allow_blank %}
24+
<div class="radio">
25+
<label>
26+
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %} />
27+
{{ none_choice }}
28+
</label>
29+
</div>
30+
{% endif %}
1431
{% for key, text in field.choices.items %}
1532
<div class="radio">
1633
<label>
17-
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %}>
34+
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %} />
1835
{{ text }}
1936
</label>
2037
</div>

rest_framework/templates/rest_framework/inline/radio.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
1+
{% load i18n %}
2+
{% trans "None" as none_choice %}
3+
14
<div class="form-group {% if field.errors %}has-error{% endif %}">
25
{% if field.label %}
36
<label class="sr-only">{{ field.label }}</label>
47
{% endif %}
8+
{% if field.allow_null or field.allow_blank %}
9+
<div class="radio">
10+
<label>
11+
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %}>
12+
{{ none_choice }}
13+
</label>
14+
</div>
15+
{% endif %}
516
{% for key, text in field.choices.items %}
617
<div class="radio">
718
<label>

rest_framework/templates/rest_framework/vertical/radio.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1+
{% load i18n %}
2+
{% trans "None" as none_choice %}
3+
14
<div class="form-group {% if field.errors %}has-error{% endif %}">
25
{% if field.label %}
36
<label {% if style.hide_label %}class="sr-only"{% endif %}>{{ field.label }}</label>
47
{% endif %}
58
{% if style.inline %}
69
<div>
10+
{% if field.allow_null or field.allow_blank %}
11+
<label class="radio-inline">
12+
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %} />
13+
{{ none_choice }}
14+
</label>
15+
{% endif %}
716
{% for key, text in field.choices.items %}
817
<label class="radio-inline">
918
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %}>
@@ -12,6 +21,14 @@
1221
{% endfor %}
1322
</div>
1423
{% else %}
24+
{% if field.allow_null or field.allow_blank %}
25+
<div class="radio">
26+
<label>
27+
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %} />
28+
{{ none_choice }}
29+
</label>
30+
</div>
31+
{% endif %}
1532
{% for key, text in field.choices.items %}
1633
<div class="radio">
1734
<label>

0 commit comments

Comments
 (0)