Skip to main content
Solved

How to keep focus on a field with the modern UI?

  • January 31, 2026
  • 3 replies
  • 64 views

Forum|alt.badge.img

Hello Everyone,

In Classic UI I have a form with a field where the user inputs a barcode and the backend adds a new line in a grid with the proper record.

The focus returns to the input field after adding the line for the user to capture the next line.

However I haven’t found a way to get this done with the modern UI.

It used to be a very simple JS code in the aspx:

<script>
function FormView_Load(): void {

    px_callback.addHandler(setFocusOnCB);

}

let setFocus: boolean = false;

function setFocusOnCB(context?: any, error?: any): void {

    if (setFocus === true) {

        setFocus = false;

        const cb = px_alls["edCBField"];

        cb.focus();

    }

}
</script>

 Has anyone figure this out ?

Best answer by harutyungevorgyan

Hello ​@albertobello83 ,

 

To ensure a field is focused every time a screen opens, you can simply use class="default-control" on that field. However, if you are losing focus specifically after a scan, I recommend checking the files for the SO302020 screen. The Pick, Pack, and Ship scan field handles exactly what you're describing, so you can see how Acumatica manages it there, and do it in the same way.

3 replies

harutyungevorgyan
Jr Varsity I
Forum|alt.badge.img+4

Hello ​@albertobello83 ,

 

To ensure a field is focused every time a screen opens, you can simply use class="default-control" on that field. However, if you are losing focus specifically after a scan, I recommend checking the files for the SO302020 screen. The Pick, Pack, and Ship scan field handles exactly what you're describing, so you can see how Acumatica manages it there, and do it in the same way.


Forum|alt.badge.img
  • Author
  • Freshman II
  • January 31, 2026

@harutyungevorgyan,

Beautiful man!!

As simple as that. But it never came to me.

Have a beer on me!


Forum|alt.badge.img
  • Freshman II
  • February 2, 2026

In Classic UI, focus could be set using ASPX JavaScript (px_callback, px_alls, etc.).

This approach does not work in Modern UI because it is React-based and does not allow client-side DOM or focus manipulation.

There is no direct Modern UI equivalent to setting focus via JavaScript.

Recommended approach in Modern UI:

Set the barcode field with CommitChanges = true

Handle logic in FieldUpdated

Add the grid line in the backend

Clear the barcode field after processing

When the field is cleared, Modern UI automatically returns focus to the same field.

protected virtual void _(Events.FieldUpdated<HeaderDAC, HeaderDAC.usrBarcode> e)

{

if (string.IsNullOrEmpty(e.Row?.UsrBarcode)) return;

 

AddLineFromBarcode(e.Row.UsrBarcode);

e.Row.UsrBarcode = null; // focus returns automatically

}