Use of HTML autofocus attribute in admin (#27692)

194 views
Skip to first unread message

Tim Graham

unread,
Jan 6, 2017, 12:48:12 PM1/6/17
to Django developers (Contributions to Django itself)
As part of removing inline JavaScript in the admin [0], snippets such as document.getElementById("id_old_password").focus() were replaced with the HTML5 autofocus attribute.

This attribute has a possibly undesired behavior [1]: "Warning: this attribute will force a page scroll to the field with the autofocus attribute set, even within an iframe. So: know your audience, know the position of the form."

This attribute could be problematic on the change list's admin's search box: "When coming back to the list screen from the edit screen, the browser normally remembers your scroll position and restores it. This is desirable behavior if you want to work through a long lists of objects. However, when you include a search field in the list screen, it has autofocus enabled, which prevents the scroll position from being restored. This is annoying and unhelpful." [2]

Do you think we should remove autofocus from the search box to remedy this complaint (and possibly go back to using JavaScript for that) or are there any better solutions here?

Adam Johnson

unread,
Jan 6, 2017, 12:54:54 PM1/6/17
to Django developers (Contributions to Django itself)
I think we should remove it and maybe add the Javascript back, this is going to affect many peoples' workflows, some of whom are in my organization.

Karen Tracey

unread,
Jan 6, 2017, 7:22:10 PM1/6/17
to django-d...@googlegroups.com
On Fri, Jan 6, 2017 at 12:48 PM, Tim Graham <timog...@gmail.com> wrote:
Do you think we should remove autofocus from the search box to remedy this complaint (and possibly go back to using JavaScript for that) or are there any better solutions here?

I personally find the existing auto-focus behavior more annoying than helpful, as it seems I'm much more likely to want to navigate by cursor or page down than search when I land on an admin list page, and it forces me to first get the focus away from the search box before I can do what I want. So I wouldn't mind if auto-focus went away entirely.

Having it not only grab the focus but scroll back to to the top of the page would be extraordinarily annoying, let's please avoid doing that.

Ciske Boekelo

unread,
Jan 8, 2017, 3:34:24 PM1/8/17
to Django developers (Contributions to Django itself)
I just found out that's it not new behavior in Django 1.9. The javascript autofocus that existed previously has the same effect. This doesn't change my request though, I'd still like the autofocus to be either removed or optional.

Op vrijdag 6 januari 2017 18:54:54 UTC+1 schreef Adam Johnson:

Adam Johnson

unread,
Jan 9, 2017, 3:21:15 AM1/9/17
to django-d...@googlegroups.com
I just found out that's it not new behavior in Django 1.9. The javascript autofocus that existed previously has the same effect.

Oh yeah, so it does. Yes it's still annoying but changing the default could be more confusing. If there were a way to autofocus on first page load only that would be the best, it might be possible with JS.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/d02bfbaa-be99-46da-9a11-a8fad7fac7cc%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Adam

Alexander Lyabah

unread,
Sep 5, 2017, 9:50:53 AM9/5/17
to Django developers (Contributions to Django itself)
> If there were a way to autofocus on first page load only that would be the best, it might be possible with JS.

Yes, It should be possible by parsing document.referrer in JS.


On Monday, January 9, 2017 at 10:21:15 AM UTC+2, Adam Johnson wrote:
I just found out that's it not new behavior in Django 1.9. The javascript autofocus that existed previously has the same effect.

Oh yeah, so it does. Yes it's still annoying but changing the default could be more confusing. If there were a way to autofocus on first page load only that would be the best, it might be possible with JS.
On 8 January 2017 at 20:33, Ciske Boekelo <cfbo...@gmail.com> wrote:
I just found out that's it not new behavior in Django 1.9. The javascript autofocus that existed previously has the same effect. This doesn't change my request though, I'd still like the autofocus to be either removed or optional.

Op vrijdag 6 januari 2017 18:54:54 UTC+1 schreef Adam Johnson:
I think we should remove it and maybe add the Javascript back, this is going to affect many peoples' workflows, some of whom are in my organization.

On Friday, January 6, 2017 at 5:48:12 PM UTC, Tim Graham wrote:
As part of removing inline JavaScript in the admin [0], snippets such as document.getElementById("id_old_password").focus() were replaced with the HTML5 autofocus attribute.

This attribute has a possibly undesired behavior [1]: "Warning: this attribute will force a page scroll to the field with the autofocus attribute set, even within an iframe. So: know your audience, know the position of the form."

This attribute could be problematic on the change list's admin's search box: "When coming back to the list screen from the edit screen, the browser normally remembers your scroll position and restores it. This is desirable behavior if you want to work through a long lists of objects. However, when you include a search field in the list screen, it has autofocus enabled, which prevents the scroll position from being restored. This is annoying and unhelpful." [2]

Do you think we should remove autofocus from the search box to remedy this complaint (and possibly go back to using JavaScript for that) or are there any better solutions here?

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.



--
Adam
Reply all
Reply to author
Forward
0 new messages