Page 1 of 1

Go back to nuuserhome after saving

Posted: Sun Feb 25, 2018 12:19 pm
by toms
Hi,

After a save action is triggered, I'd like to redirect the user back to nuuserhome.

The workflow would go like this:

1. The user clicks a button on nuuserhome
2. A new record is opened (Edit Form)
3. The record is saved by the user
4. --> The user is directed back to nuuserhome

I wrote a function that takes the user back to nuuserhome. Where would be the best place to call this function?

Code: Select all

function goBackToUserHome() {
if (nuFORM.getCurrent().form_code == 'nuuserhome') {return;}
var b = window.nuFORM.breadcrumbs.length;
for (var i = 0 ; i < b ; i++){
   if (window.nuFORM.breadcrumbs[i].form_code == 'nuuserhome') {
      nuGetBreadcrumb(i);
      return;
   }
 }
}

Re: Go back to nuuserhome after saving

Posted: Tue Feb 27, 2018 1:13 am
by admin
toms,

You could use nuGetBreadcrumb(0).

http://wiki.nubuilder.net/nubuilderfort ... Breadcrumb

Steven

Re: Go back to nuuserhome after saving

Posted: Tue Feb 27, 2018 5:00 am
by toms
Steven,
admin wrote:You could use nuGetBreadcrumb(0).
While this would work in most cases, breadcrumb 0 is not necessarily always nuuserhome. E.g. when you login automatically passing f/r parameters or while you are logged in as 'globeadmin'
That's why I wrote this goBackToUserHome() function.

Code: Select all

Where would be the best place to call this function? 
My question was, where to call this function from? After a user has hit "save" I need to know when the saving action is done so I can call goBackToUserHome().

Re: Go back to nuuserhome after saving

Posted: Tue Feb 27, 2018 7:39 pm
by admin
toms,

OK, Good question.

You need to call your Javascript in the Javascript section of the Form.

But in the flowchart below, squares 1, 2 and 3 is Javascript from the same Form.
flow3.png
So you'll need to use if statements to know where it is running.

Code: Select all

if(nuFormType() == 'browse'){
   //-- Box 1
}else{

   if(nuIsSaved()){
      //-- Box 3
   }else{
      //-- Box 2
   }

}
I have just added nuIsSaved()... http://wiki.nubuilder.net/nubuilderfort ... #nuIsSaved

So, to go back to another Breadcrumb after you have Saved a record, you'll need to check you are in Box 3.


Steven

Re: Go back to nuuserhome after saving

Posted: Wed Feb 28, 2018 5:39 am
by toms
Perfect, it works as expected!

Re: Go back to nuuserhome after saving

Posted: Wed Feb 28, 2018 6:49 am
by admin
.