web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Technical: Is it possible to keep the cursor on the field after validating it?

(0) ShareShare
ReportReport
Posted on by 450

Hi,

This is a more technical question so not sure how to really ask them here but in short what i'm trying to achieve:

If I validate a field in Business Central by default the cursor moves to the next field. Now what I'm trying to do is: if I validate a specific field, is it possible in code to keep my cursor on that field after validating it?

Thanks in advance.

Regards

  • Suggested answer
    Andy Sather Profile Picture
    Microsoft Employee on at

    Hello  - We currently do not have dedicated Dev support via the Dynamics 365 Business Central forums, but I wanted to provide you some additional resources to assist.  If you need assistance with debugging or coding I would recommend discussing this on one of our communities.

    www.yammer.com/dynamicsnavdev

    dynamicsuser.net/.../developers

    I will open this up to the community in case they have something to add.

  • Terrance Morgan Profile Picture
    515 on at

    Add a class (something like input-error) for every invalid field. Then use something like:

    var errors = document.querySelectorAll(".input-error");

    if (errors.length > 0) {

    errors[0].focus();

    }

    Here's an example: http://jsfiddle.net/NtHzV/1/

    It really all depends on the structure of your code, how you're validating, what you're actually doing with validation, and what your HTML is.

    At the same time, if you're doing something similar to my example, you might as well keep track of the first input with an error, then focus() it at the end of validation. Something like this:

    http://jsfiddle.net/NtHzV/2/

    UPDATE:

    Bergi pointed out that querySelector might as well be used (instead of querySelectorAll) because you're only looking for the first input with errors. So here's an update:

    var error_input = input_area.querySelector(".input-error");

    if (error_input !== null) {

    error_input.focus();

    }

    http://jsfiddle.net/NtHzV/3/

    Here are specs on querySelector: developer.mozilla.org/.../element.querySelector - Note that < IE8 does not support it.

    The use of ".input-error" is because that is the CSS class selector, and will find the first (if any) element in a specific area with the class "input-error".


    --
    Terrance | Apps4Rent

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 710 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 387 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 385 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans