Page 1 of 1

Assistance needed- Return home & pull username

Posted: Fri Jul 06, 2018 5:10 pm
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.

Re: Assistance needed- Return home & pull username

Posted: Fri Jul 06, 2018 5:32 pm
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)

Re: Assistance needed- Return home & pull username

Posted: Wed Jul 11, 2018 3:20 am
by admin
.

Re: Assistance needed- Return home & pull username

Posted: Wed Aug 08, 2018 5:58 pm
by toms
@Wesleyitguru, my codes to return home will no longer work with a recent change in github.
nuIsSaved() now returns unexpected results.

Re: Assistance needed- Return home & pull username

Posted: Fri Aug 10, 2018 8:03 pm
by admin
.