Welcome to the nuBuilder Forums!

Join our community by registering and logging in.
As a member, you'll get access to exclusive forums, resources, and content available only to registered users.

Prevent form position reset upon save Topic is solved

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
Paul
Posts: 21
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 6 times
Been thanked: 1 time

Prevent form position reset upon save

Unread post by Paul »

I have a custom 'Save' button on my form and it works fine. However, when the button is clicked the data is saved but the form gets scrolled to the top of the page. I'd like to stay in the same place where I was before I clicked the 'Save' button. How do I accomplish this?
steven
Posts: 385
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 56 times
Been thanked: 53 times

Re: Prevent form position reset upon save

Unread post by steven »

Hi Paul,

You could place this in the Form's Browse & Edit or Edit JavaScript.

Code: Select all


if(window.previousID != null || window.previousID === undefined){
    $('#'+window.previousID).focus();
    
}

document.addEventListener('focusout', (event) => {
    
    if(event.target.id != 'nuSaveButton'){
        window.previousID = event.target.id;
    }
    
});




Steven
A short post is a good post.
Paul
Posts: 21
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 6 times
Been thanked: 1 time

Re: Prevent form position reset upon save

Unread post by Paul »

If I put the 'Save' button near the bottom of the form, then the provided code works. However, if I place it in the middle of the form, then it does not.
steven
Posts: 385
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 56 times
Been thanked: 53 times

Re: Prevent form position reset upon save

Unread post by steven »

Hi Paul,

I'm unclear on what you are trying to do.

You said
If I put the 'Save' button near the bottom of the form,
Can you share some screen shots?


Steven
A short post is a good post.
kev1n
nuBuilder Team
Posts: 4449
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 488 times
Contact:

Re: Prevent form position reset upon save

Unread post by kev1n »

Also try this approach:

Code: Select all

if (nuHasBeenSaved() > 0) {
    // Restore the scroll position
    window.scrollTo(0, window.scrollTop);
}

function nuBeforeSave() {
    // Get current vertical scroll position
    window.scrollTop = window.scrollY;
    return true; // Allow the save to proceed
}
Paul
Posts: 21
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 6 times
Been thanked: 1 time

Re: Prevent form position reset upon save

Unread post by Paul »

I have two Save buttons on the form, one in the middle and one near the bottom. The form is a long one. That is the reason why I want additional Save buttons.

Per your instructions, I have placed your code (first version) in the Form's Browse & Edit JavaScript area.
If I click the first one, focus jumps to the top - not what I want.
If I click on the lower one, the focus remains where it is.
Last edited by Paul on Thu Sep 04, 2025 6:24 am, edited 1 time in total.
Paul
Posts: 21
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 6 times
Been thanked: 1 time

Re: Prevent form position reset upon save

Unread post by Paul »

The second bit of code works. Tried it several times with both Save buttons. Thanks!
kev1n
nuBuilder Team
Posts: 4449
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 75 times
Been thanked: 488 times
Contact:

Re: Prevent form position reset upon save

Unread post by kev1n »

Instead of adding more Save buttons, make the Action Holder—the toolbar with actions like Save and Delete—sticky so it stays visible at the top as you scroll down the page.

To do so, add the following CSS under Setup → Style:

Code: Select all

.nuBreadcrumbHolder {
  position: sticky;
  top: 0;
  z-index: 1000;
}

.nuActionHolder {
  position: sticky;
  top: 33px;
  z-index: 999;
}
Paul
Posts: 21
Joined: Mon Aug 25, 2025 6:03 am
Has thanked: 6 times
Been thanked: 1 time

Re: Prevent form position reset upon save

Unread post by Paul »

Very cool! Thank you!
Post Reply