Welcome to the nuBuilder Forums!

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

Start new form with prefilled data taken from other form

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Start new form with prefilled data taken from other form

Unread post by Janusz »

I want to create a new record on new form with prefilled data taken from the current form.

Currently on one form lets say Form_1 I have a button with run command to open other form lets say Form_2 to enter a new record on it.
To have blank Form_2 I use - non existing value in the search field. And later I have to choose manually the reference with the "Lookup".

so the question - how to set-up on Form_2 in just in one field a value taken from one field from the Form_1.

So after Button press on Form_1 to have following sequence -> read value from Object_A on Form_1 -> Open Form_2 -> set value on Form_2 to Object_X equal to Object_A
If you like nuBuilder, please leave a review on SourceForge
ARWEN
Posts: 78
Joined: Thu Nov 01, 2018 6:01 am

Re: Start new form with prefilled data taken from other form

Unread post by ARWEN »

Question: Is Form 2 openend in a popup window (iframe)? Then you can try something like this:

// add in form 2, custom JavaScript code:

Code: Select all

if (nuFormType() == 'edit') {
    // get value of object_A 
    var objectA = $("#object_A", window.parent.document); 
   // assign the value to object X
     $("#object_X').val(objectA).change();
}
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Start new form with prefilled data taken from other form

Unread post by Janusz »

Hi,
So far I was not able to link both forms.

Generally the problem I have is with the folowing line: var objectA = $("#object_A", window.parent.document);
(as objectA I use the value from the input field named ID which in my case is equivallent to the first column name of the table)

I was trying to make some modification to it, some other code like:
window.parent.document.getElementById('object_A')

but did not manage to make it working. Sometimes in the target field I have sothing like: [object Object]

do you have some more ideas how to proceed.

>>> more clarification to my case. I have full screen edit window on which there are some input fields and a button to open new window in a full screen mode. I want to read a value from one input field from the parent window and to place it in one field in opened window. The issue I have is - how to read a value from the parent window.
If you like nuBuilder, please leave a review on SourceForge
ARWEN
Posts: 78
Joined: Thu Nov 01, 2018 6:01 am

Re: Start new form with prefilled data taken from other form

Unread post by ARWEN »

There was a val() missing in my code

Code: Select all

if (nuFormType() == 'edit') {
    // get value of object_A 
    var objectA = $("#object_A", window.parent.document).val();
   // assign the value to object X
     $("#object_X').val(objectA).change();
}
and a button to open new window in a full screen mode.
What code is run in the button? What do you mean by "full screen mode" ? My code will only work if the 2nd window is opened in a popup window (iFrame)
Screenshots might be of help.
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Start new form with prefilled data taken from other form

Unread post by Janusz »

Hi, please find enclosed a file with the issue I am trying to resolve.
The main point is how to read value "2" on "Form A" with code placed in "Form B"

https://drive.google.com/file/d/1VcfnSF ... sp=sharing

so far I did not succeed with it.
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Start new form with prefilled data taken from other form

Unread post by kev1n »

IMO there's no direct way to get a value from form A once form B is open. What I usually do is save the value before opening the 2nd form using Web Storage API.

To do so, change your existing button from Run type to Input type Button. Then add an onclick event:

Code: Select all

sessionStorage.setItem("Kontakty_id", $('#Kontakty_id').val()); nuForm('5c32367d36711a9','-1','', '');
(Replace 5c32367d36711a9 with the id of the Form B)

Then in Form 2, retrieve the value from session storage and assign it to cta_kont_ref

Code: Select all

if(nuFormType() == 'edit') {
    // set address if opened from an address
    var refA = sessionStorage.getItem("Kontakty_id");
    if(refA !== null) {
        $('#cta_kont_ref').val(refA).change();
    }
}
// Remove session storage
sessionStorage.removeItem("Kontakty_id");
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Start new form with prefilled data taken from other form

Unread post by Janusz »

Working now - :-) - THANKS a lot.

but I was trying a lot with no success due to not proper assign of the form Id in my application,
for the following part of code:

Code: Select all

 ... nuForm('5c32367d36711a9','-1','', '');
and finally I used the method from
https://forums.nubuilder.cloud/viewtopic.php?f=19&t=9787

what solved the issue.
If you like nuBuilder, please leave a review on SourceForge
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Start new form with prefilled data taken from other form

Unread post by admin »

.
Post Reply