Skip to content

Commit e34fd99

Browse files
Made TemplateHTMLRenderer render IntegerField inputs when value is 0. (#5834)
* Fix 0 value IntegerField in TemplateHTMLRenderer Signed-off-by: Nikhil Sheoran <[email protected]> * Remove unnecessary `field.value != “”` check * Adjust test case Uses `vertical` templates only.
1 parent da535d3 commit e34fd99

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

rest_framework/templates/rest_framework/horizontal/input.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{% endif %}
77

88
<div class="col-sm-10">
9-
<input name="{{ field.name }}" {% if style.input_type != "file" %}class="form-control"{% endif %} type="{{ style.input_type }}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value %}value="{{ field.value }}"{% endif %} {% if style.autofocus and style.input_type != "hidden" %}autofocus{% endif %}>
9+
<input name="{{ field.name }}" {% if style.input_type != "file" %}class="form-control"{% endif %} type="{{ style.input_type }}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value is not None %}value="{{ field.value }}"{% endif %} {% if style.autofocus and style.input_type != "hidden" %}autofocus{% endif %}>
1010

1111
{% if field.errors %}
1212
{% for error in field.errors %}

rest_framework/templates/rest_framework/inline/input.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
</label>
66
{% endif %}
77

8-
<input name="{{ field.name }}" {% if style.input_type != "file" %}class="form-control"{% endif %} type="{{ style.input_type }}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value %}value="{{ field.value }}"{% endif %} {% if style.autofocus and style.input_type != "hidden" %}autofocus{% endif %}>
8+
<input name="{{ field.name }}" {% if style.input_type != "file" %}class="form-control"{% endif %} type="{{ style.input_type }}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value is not None %}value="{{ field.value }}"{% endif %} {% if style.autofocus and style.input_type != "hidden" %}autofocus{% endif %}>
99
</div>

rest_framework/templates/rest_framework/vertical/input.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<label {% if style.hide_label %}class="sr-only"{% endif %}>{{ field.label }}</label>
44
{% endif %}
55

6-
<input name="{{ field.name }}" {% if style.input_type != "file" %}class="form-control"{% endif %} type="{{ style.input_type }}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value %}value="{{ field.value }}"{% endif %} {% if style.autofocus and style.input_type != "hidden" %}autofocus{% endif %}>
6+
<input name="{{ field.name }}" {% if style.input_type != "file" %}class="form-control"{% endif %} type="{{ style.input_type }}" {% if style.placeholder %}placeholder="{{ style.placeholder }}"{% endif %} {% if field.value is not None %}value="{{ field.value }}"{% endif %} {% if style.autofocus and style.input_type != "hidden" %}autofocus{% endif %}>
77

88
{% if field.errors %}
99
{% for error in field.errors %}

tests/test_bound_fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class ExampleSerializer(serializers.Serializer):
151151
'<legend>Nested1</legend>'
152152
'<divclass="form-group">'
153153
'<label>Textfield</label>'
154-
'<inputname="nested2.nested1.text_field"class="form-control"type="text">'
154+
'<inputname="nested2.nested1.text_field"class="form-control"type="text"value="">'
155155
'</div>'
156156
'</fieldset>'
157157
'<divclass="form-group">'

0 commit comments

Comments
 (0)