⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Focus to first field after insert?



lherlaar

lherlaar
  • profile picture
  • Member

Posted 28 April 2012 - 11:49 AM

When you add a record using the flexigrid theme, all form fields get cleared after pressing enter. Clearing the fields is convenient, as it enables you to quickly add another record, without returning to the list view first.

However, I noticed that the focus stays on the field where you pressed the enter button. Wouldn't it be more convenient/logical to set the focus to the first edit field of the now empty form after adding the new record? In that way, you don't need to reach for the mouse to set the focus to the first field to start entering another record.

(Of course, this should not happen in editing mode, only after adding a record. In editing mode the form fields currently keep their content, which is good, and keeping the focus on the last edited field is what you'd expect, IMHO.)

SandZ

SandZ
  • profile picture
  • Member

Posted 28 April 2012 - 14:23 PM

You can add it in your JS, where you should catch jquery event

lherlaar

lherlaar
  • profile picture
  • Member

Posted 04 May 2012 - 21:17 PM

Ok, I got it.

In assets/grocery_crud/themes/flexigrid/js/flexigrid-add.js there on line 42, you'll find this statement:

clearForm();

This is where the form gets cleared after a successful insert. I added this line (line number 45), which does the trick:

$("form input:visible:first").focus();

It selects the first visible input of the form and sets the focus to that field.

Charles A.

Charles A.
  • profile picture
  • Member

Posted 09 June 2013 - 19:33 PM

What about datatables theme? How I can set focus on the first element on an add/edit operation? Thank you very much!!