Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Assistance needed- Return home & pull username

Questions related to using nuBuilder Forte.
Post Reply
Wesleyitguru
Posts: 7
Joined: Thu Jul 05, 2018 3:45 pm

Assistance needed- Return home & pull username

Unread post by Wesleyitguru »

So I am making steady progress getting my projects working as I need on Nubuilder Forte, and with the help of the search function on the forum I am getting a lot right with my lack of JavaScript knowledge.

I just have two problems:
1. I have added the following code to automatically populate the username field on my form, and it is working 100%.

Code: Select all

function getUserName(){
    var u = nuUserName();
    if ( u == null) {
        u= "globeadmin";
        }
    return u;
}

$('#MYFIELDNAME').val(getUserName()).change();;
The problem is, if I go and edit that item with another user, it changes the username again to current user, I need to be able to keep the original user as the one that submitted the 1st entry. I'm guessing I need some sort of if statement, but I am clueless as to what it needs to be.


2. When the user saved the data for the 1st time, I would like them to return to the main page and not remain on the data they just submitted, I found the nuGetBreadcrumb(0) option, but it doesn't work correctly( more like I'm using it incorrectly probably).

Again, thanks in advanced.

P.S. As soon as the project goes into production, I will be making a donation to the project, as it has put me in a excellent position to help my clients with their specific requirements.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Assistance needed- Return home & pull username

Unread post by toms »

Hi,

This will check if the user field is empty:

Code: Select all

if ($('#MYFIELDNAME').val() == '') {
  $('#MYFIELDNAME').val(getUserName()).change();
}
This will take the user back to the previous Screen:

Code: Select all

if (nuFormType() == 'edit') {
    if (nuHasBeenSaved() === 1) { // first time saved
        gotoPrevBreadcrumb();
    }
}

function gotoPrevBreadcrumb() {
    var l = window.nuFORM.breadcrumbs.length;
    if (l > 1) {
        nuGetBreadcrumb(l - 2);
    }
}
In case you want to go back to the previous launch form, use this code:

Code: Select all

if (nuFormType() == 'edit') {
    if (nuHasBeenSaved() === 1) {
        gotoPrevLaunchform();
    }
}
function gotoPrevLaunchform() {
    var b = window.nuFORM.breadcrumbs.length - 2;
    for (var i = b; i >= 0; i--) {
        if (window.nuFORM.breadcrumbs[i].form_type == "launch") {
            nuGetBreadcrumb(i);
            return;
        }
    }
}


To return to a specific user home:

Code: Select all

if (nuFormType() == 'edit') {
    if (nuHasBeenSaved() === 1) {
        custGoBackToUserHome();
    }
}

function custGoBackToUserHome(userHomeId) {

    if (userHomeId == undefined || userHomeId == 'null') {
            var userHomeId = 'nuuserhome';
        }
		
   if (nuFORM.getCurrent().form_code == userHomeId) {
        return;
    }
    var b = window.nuFORM.breadcrumbs.length;
    for (var i = 0; i < b; i++) {
        if (window.nuFORM.breadcrumbs[i].form_code == userHomeId) {
            nuGetBreadcrumb(i);
            return;
        }
    }
}
Update: Replaced nuIsSaved() with the new function nuHasBeenSaved()
(https://wiki.nubuilder.cloud/ ... sBeenSaved)
Last edited by Anonymous on Sat Aug 11, 2018 6:16 am, edited 2 times in total.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Assistance needed- Return home & pull username

Unread post by admin »

.
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Assistance needed- Return home & pull username

Unread post by toms »

@Wesleyitguru, my codes to return home will no longer work with a recent change in github.
nuIsSaved() now returns unexpected results.
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Assistance needed- Return home & pull username

Unread post by admin »

.
Post Reply