Set focus on first field in field editor

  • 3
  • Question
  • Updated 10 months 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,738 Points 5k badge 2x thumb

Posted 5 years ago

  • 3
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k 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:



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




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