WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 2 months ago

#40302 closed defect (bug) (fixed)

Reset password field is not auto-focused

Reported by: afercia Owned by: audrasjb
Milestone: 5.9 Priority: normal
Severity: normal Version:
Component: Login and Registration Keywords: has-screenshots has-patch commit
Focuses: ui Cc:

Description

See also #40301 and #30023.

Although auto-focusing form fields can be arguable in some cases, I'd say it makes sense when there's a very specific task to accomplish and when there's no relevant content before the auto-focused field. In that case, the relevant content would be "skipped" for some users, see #40301.

Ideally, there should be some consistency. I see no reasons why, for example, the lost password field gets auto-focused and the reset password field doesn't.

As far as I see, this has always worked this way, even before the introduction of auto-generated password, because in the reset password screen there's no field with an user_pass ID.

With JS on, the field to focus has a pass1-text ID but the only relevant code in the page tries to target an element with the ID user_pass:

https://cldup.com/WGKMt1gJ8B.png

With JS off, well... I guess it's a bit pointless but the relevant field has a pass1 ID.

https://cldup.com/-V8oLmKKZF.png

Attachments (3)

40302.diff (704 bytes) - added by donmhico 2 years ago.
Patch to focus on new password field on reset password page.
40302.1.diff (749 bytes) - added by audrasjb 4 months ago.
Login and Registration: auto-focus the reset password field.
40302.2.diff (788 bytes) - added by sabernhardt 3 months ago.
using pass1 ID

Download all attachments as: .zip

Change History (15)

@donmhico
2 years ago

Patch to focus on new password field on reset password page.

#1 @donmhico
2 years ago

  • Keywords has-patch added

My patch above includes 2 changes on 2 different files.

  1. admin/user-profile.js - Inside the generatePassword() function. After the generated password was set, the new password field will be focused. The generatePassword() is also use in wp-admin/user-new.php page, but the added code below doesn't produce any unwanted behaviour.
// Focus the password field.
$($pass1Text).focus();
  1. wp-login.php - I changed login_footer( 'user_pass' ); to login_footer( 'pass1-text' );. This is to correct the target field of the code below. $input_id is the string passed in login_footer().
<script type="text/javascript">
    try{document.getElementById('<?php echo $input_id; ?>').focus();}catch(e){}
    if(typeof wpOnload=='function')wpOnload();
</script>

Reference:
https://developer.wordpress.org/reference/functions/login_footer/

#2 @SergeyBiryukov
2 years ago

  • Milestone changed from Awaiting Review to 5.3

#3 @davidbaumwald
2 years ago

  • Keywords needs-testing added

The patest patch for this ticket still needs testing. With Beta 1 of version 5.3 only a few days away, this is being moved to Future Release. If this ticket can be resolved in time for 5.3, feel free to re-milestone.

#4 @davidbaumwald
2 years ago

  • Milestone changed from 5.3 to Future Release

@audrasjb
4 months ago

Login and Registration: auto-focus the reset password field.

#5 @audrasjb
4 months ago

  • Milestone changed from Future Release to 5.9

40302.1.diff refreshes the previous patch against trunk.

Moving for 5.9 consideration.

This ticket was mentioned in Slack in #core-test by mai21. View the logs.


3 months ago

@sabernhardt
3 months ago

using pass1 ID

#7 @sabernhardt
3 months ago

Note: I used .trigger('focus') in the JS file, but the inline script still has .focus().

#8 @sabernhardt
2 months ago

  • Owner set to sabernhardt
  • Status changed from new to accepted

This ticket was mentioned in Slack in #core by sabernhardt. View the logs.


2 months ago

#10 @audrasjb
2 months ago

  • Keywords commit added; needs-testing removed

This one works fine on my side, marking as ready for commit.

#11 @audrasjb
2 months ago

  • Owner changed from sabernhardt to audrasjb
  • Status changed from accepted to assigned

Self-assigning for final testing then commit.

#12 @audrasjb
2 months ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 52193:

Login and Registration: auto-focus the reset password field.

Although auto-focusing form fields can be arguable in some cases, it makes sense when there is a very specific task to accomplish and when there is no relevant content before the auto-focused field.

This change brings consistency between various forms generated by wp-login.php.

Props afercia, donmhico, sabernhardt.
Fixes #40302.

Note: See TracTickets for help on using tickets.