Skip to content

Commit befacfb

Browse files
jamesbeithtomchristie
authored andcommitted
Add autofocus support for input.html templates (#4650)
This change adds support to use `'autofocus': True` in the style options and have the `autofocus` attribute included on the input field when rendered.
1 parent 0b93040 commit befacfb

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

docs/topics/html-and-forms.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Let's take a look at how to render each of the three available template packs. F
108108
class LoginSerializer(serializers.Serializer):
109109
email = serializers.EmailField(
110110
max_length=100,
111-
style={'placeholder': 'Email'}
111+
style={'placeholder': 'Email', 'autofocus': True}
112112
)
113113
password = serializers.CharField(
114114
max_length=100,
@@ -207,9 +207,9 @@ Field templates can also use additional style properties, depending on their typ
207207

208208
The complete list of `base_template` options and their associated style options is listed below.
209209

210-
base_template | Valid field types | Additional style options
210+
base_template | Valid field types | Additional style options
211211
----|----|----
212-
input.html | Any string, numeric or date/time field | input_type, placeholder, hide_label
212+
input.html | Any string, numeric or date/time field | input_type, placeholder, hide_label, autofocus
213213
textarea.html | `CharField` | rows, placeholder, hide_label
214214
select.html | `ChoiceField` or relational field types | hide_label
215215
radio.html | `ChoiceField` or relational field types | inline, hide_label

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 %}>
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 %}>
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 %}>
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 %}>
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 %}>
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 %}>
77

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy