Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

Using Tab-Key to move to next form field undoes onChange?

Posted on by 31
Hello everyone,

Please be so kind as to read my full post before responding.
Thank you for your consideration.

With a colleague of mine I recently stumbled upon a very strange behaviour with one simple Javacript form customization.
In a custom form for work orders (msyn_workorder), there's a custom field to store work duration in 8-hour units (kk_duration) (that's the unit our technical staff offers services in).
There is a small JavaScript customization in place to calculate minutes from that field and store it in the the out-of-the-box-field (msdyn_primaryincidentestimatedduration), which then also shows the duration in a more readable format, see screenshot.
Simple code:
 
function onChange_kk_duration(eventContext) {
    const formContext = eventContext.getFormContext();
    var duration = formContext.getAttribute('kk_duration')?.getValue();
    if (duration && duration > 0) {
        formContext.getAttribute('msdyn_primaryincidentestimatedduration')?.setValue(Math.round(duration * 480));
    }
}

This basically works with one small caveat:
My colleague likes to switch to the next form field using the /Tab/-Key.
When he uses that after filling in the kk_duration Field and triggering onChange, msdyn_primaryincidentestimatedduration seems to reset to the previous value.
He uses Chrome as his browser, I use Firefox and we can both reproduce this strange behaviour consistently.
When using the mouse to click away or using enter to confirm the input and stay in kk_duration, there's no problem.
It seems to only occur when using tab to navigate.

Example: fill first field, tab onChange triggers, tab value resets
////

Any ideas on what makes /Tab/ cause this reset?

Thanks,
    Sa.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans