Set focus on first field in field editor

  • 3
  • Question
  • Updated 2 years ago
  • Answered
I have a "New Account" page with a field editor in it. When the page loads, I want the first field to get the focus, so that the user can immediately start typing the name of the new account.

Do I need some Javascript to magic this?
Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,808 Points 5k badge 2x thumb

Posted 7 years ago

  • 3
Photo of Zach McElrath

Zach McElrath, Employee

  • 56,134 Points 50k badge 2x thumb
Official Response
Glenn, this is a great idea. We've been experimenting with what the best logic is to implement this, as everyone's pages can be so different that it's hard to determine what the "first field" is on a given page.

However, for scenarios like your "New Account" example, it's quite easy to identify the "first field", and likewise quite easy, with a simple Inline JavaScript resource, to assign focus. Here's what you do:

(1) Create a new Inline JavaScript resource in your page, with the following body:

var $ = skuid.$;
$('.nx-field > input').first().focus();

That's it! You should get a cursor in the first field.