Feature #13134

Focus first text field automatically

Added by Harry Garrood about 5 years ago. Updated almost 3 years ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:Jean-Philippe Lang% Done:

0%

Category:UI
Target version:2.5.0
Resolution:Fixed

Description

The attached patch uses JS to focus the Name field in the versions/_form partial. Based on trunk r11352.

Also I grepped through 'test' for the string 'focus', to see if this kind of stuff is tested, and didn't find anything; hence, no tests.

autofocus_version_name.patch Magnifier (309 Bytes) Harry Garrood, 2013-02-12 00:59


Related issues

Related to Redmine - Defect #17757: Link with hash does not work on Firefox Closed

Associated revisions

Revision 12670
Added by Jean-Philippe Lang over 4 years ago

Focus first text field automatically (#13134).

History

#1 Updated by Daniel Felix about 5 years ago

Well I would agree that this would work. But another idea is to use the HTML5 autofocus function, which won't work on older browsers but would work even without js.

The tag could be included on systems with some older browser engine (for example IE7,8,9).

The tag is quite simple:
autofocus="autofocus"

Example:
<input type="text" id="search" autofocus="autofocus" />

#2 Updated by Harry Garrood about 5 years ago

JS seems to makes more sense to me, since:

  • Redmine doesn't work without JS anyway -- this patch should work with all Redmine-capable browser setups
  • The only IE to support HTML5 autofocus is IE10
  • It's consistent; this JS is used in other places in Redmine (eg issues/new)

#3 Updated by Daniel Felix about 5 years ago

Harry Garrood wrote:

  • Redmine doesn't work without JS anyway -- this patch should work with all Redmine-capable browser setups

Right, it will work. But I personally would use this just as fallback if there is no build-in property. But maybe just my own thinking. :-)

  • The only IE to support HTML5 autofocus is IE10

Yes, and all other major Browsers use this.
See: http://www.wufoo.com/html5/attributes/02-autofocus.html

  • It's consistent; this JS is used in other places in Redmine (eg issues/new)

You're right. But on the other Hand, it would be quite good to be able to use Redmine without any JS, too. :-)

#4 Updated by Jean-Philippe Lang about 5 years ago

Another approach that would prevent autofocus attributes or js in each view would be add a few js lines in application.js to automatically focus the first input[type=text] that is found in the page content. What do you think?

#5 Updated by Daniel Felix about 5 years ago

Jean-Philippe Lang wrote:

Another approach that would prevent autofocus attributes or js in each view would be add a few js lines in application.js to automatically focus the first input[type=text] that is found the page content. What do you think?

Well, this would be also some approach which would prevent bigger codechanges.

#6 Updated by Etienne Massip about 5 years ago

Jean-Philippe Lang wrote:

Another approach that would prevent autofocus attributes or js in each view would be add a few js lines in application.js to automatically focus the first input[type=text] that is found in the page content. What do you think?

Maybe autofocus on first input having a tabindex value > 0 set and fallback to the first text input if none found?

FWIW, I like the use of HTML5 autofocus attribute as Daniel suggested.

#7 Updated by Jean-Philippe Lang over 4 years ago

  • Tracker changed from Patch to Feature
  • Subject changed from Autofocus version name in versions/_form.html.erb to Focus first text field automatically
  • Status changed from New to Closed
  • Assignee set to Jean-Philippe Lang
  • Target version set to 2.5.0
  • Resolution set to Fixed

Javascript added in r12670. It sets focus to the first text field unless a field has focus already.

#8 Updated by b b almost 3 years ago

Hi, this modification break the anchors on links like this one :

https://core.spip.net/projects/spip/repository/entry/spip/ecrire/inc/utils.php#L404

Since the first input text get the focus, the anchor in the link doesn't "works".

If we comment http://www.redmine.org/projects/redmine/repository/revisions/12670/diff/trunk/public/javascripts/application.js the anchor works well.

#9 Updated by Toshi MARUYAMA almost 3 years ago

b b wrote:

Hi, this modification break the anchors on links like this one :

https://core.spip.net/projects/spip/repository/entry/spip/ecrire/inc/utils.php#L404

Since the first input text get the focus, the anchor in the link doesn't "works".

If we comment http://www.redmine.org/projects/redmine/repository/revisions/12670/diff/trunk/public/javascripts/application.js the anchor works well.

I created issue #17757.

#10 Updated by Toshi MARUYAMA almost 3 years ago

  • Related to Defect #17757: Link with hash does not work on Firefox added

Also available in: Atom PDF