Skip to content

Commit fdd811e

Browse files
committed
Allow blank/null on radio.html choices
1 parent 9329981 commit fdd811e

File tree

1 file changed

+18
-2
lines changed
  • rest_framework/templates/rest_framework/horizontal

1 file changed

+18
-2
lines changed

rest_framework/templates/rest_framework/horizontal/radio.html

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
1+
{% load i18n %}
2+
13
<div class="form-group">
24
{% if field.label %}
35
<label class="col-sm-2 control-label {% if style.hide_label %}sr-only{% endif %}">{{ field.label }}</label>
46
{% endif %}
57
<div class="col-sm-10">
68
{% if style.inline %}
9+
{% if field.allow_null or field.allow_blank %}
10+
<label class="radio-inline">
11+
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %} />
12+
{% trans "None" %}
13+
</label>
14+
{% endif %}
715
{% for key, text in field.choices.items %}
816
<label class="radio-inline">
9-
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %}>
17+
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %} />
1018
{{ text }}
1119
</label>
1220
{% endfor %}
1321
{% else %}
22+
{% if field.allow_null or field.allow_blank %}
23+
<div class="radio">
24+
<label>
25+
<input type="radio" name="{{ field.name }}" value="" {% if not field.value %}checked{% endif %} />
26+
{% trans "None" %}
27+
</label>
28+
</div>
29+
{% endif %}
1430
{% for key, text in field.choices.items %}
1531
<div class="radio">
1632
<label>
17-
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %}>
33+
<input type="radio" name="{{ field.name }}" value="{{ key }}" {% if key == field.value %}checked{% endif %} />
1834
{{ text }}
1935
</label>
2036
</div>

0 commit comments

Comments
 (0)