Welcome to the nuBuilder Forums!

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

Insert values from one form to another one

Questions related to using nuBuilder Forte.
Locked
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Insert values from one form to another one

Unread post by marcvander »

Hey,

Toms helped me already regarding a similar question: https://forums.nubuilder.cloud/viewtopic. ... 5&start=10

I'm trying to insert many fields of one form to another one. So here is what Toms gave me as a solution, worked for the primary key of the form only. On the first form:

Code: Select all

function nuSelectBrowse(e) {
    var r   = $('#' + e.target.id).attr('data-nu-primary-key');
    window.ENTREPRISE_ID = r;
    nuForm(nuGetProperty('form_id'), r, '', '', '1');   
}
And on the second form:

Code: Select all

if (nuFormType() == 'edit') {
    $("#contact_entreprise_id").val(window.ENTREPRISE_ID).change(); 
}
How can I adapt this to make it work for any value in the first form (not only the primary key)?
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Insert values from one form to another one

Unread post by admin »

marcvander,

I have 2 questions, just so I understand.

1. Are you saying that you have an Edit Form with values on it - and you would like to open another Edit Form from this Form and have it be automatically populated with some of the values on the first Edit Form?

2. Do you want this second Form to replace the first Edit Form on the screen, or do you want it to appear in a Popup window?

Steven
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: Insert values from one form to another one

Unread post by marcvander »

Hey steven,

thanks for the answer.

1- Yes exactly
2- in a popup window (but I would be interested in knowing how to replace the 1st form by the 2nd form on the screen as well)
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Insert values from one form to another one

Unread post by admin »

marcvander,

You could try something like this in the Javascript of the Popup.

Code: Select all


if(nuCurrentProperties().record_id == '-1'){  //-- a new record
        
    var n = parent.$('#cus_name').val();
    $('#inv_name').val(n);
    
    
    var p = parent.$('#cus_phone').val();
    $('#inv_phone').val(p);

}


Steven
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: Insert values from one form to another one

Unread post by marcvander »

Steven,

I tried and it works, it populates the 2nd form opened in the popup with values of the 1st form. But there is one problem: when I save the 2nd form, none of the populated values get saved.

Before save, values are populated (for Montant HT, I entered by hand 1000):
Capture d’écran 2018-06-15 à 10.19.56.png
After save, values which were auto populated are deleted, only the values entered by hand stay (in this exemple, the value 1000 for Montant HT):
Capture d’écran 2018-06-15 à 10.20.04.png
There is no error in nudebug results, and no error in JS console.
You do not have the required permissions to view the files attached to this post.
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
toms
Posts: 785
Joined: Sun Oct 14, 2018 11:25 am

Re: Insert values from one form to another one

Unread post by toms »

You need to invoke .change() otherwise the fields will not be saved.

Code: Select all

$('#inv_phone').val(p).change();
marcvander
Posts: 101
Joined: Mon Mar 26, 2018 5:57 pm

Re: Insert values from one form to another one

Unread post by marcvander »

Thanks toms, it works now. Thanks to both of you
Config:
nuBuilder v4 on a dedicated LAMP server:
-Ubuntu 14.04.5 LTS
-Apache 2.4.7
-MySQL 14.14 Distrib 5.7.22
-PHP 5.5.9-1ubuntu4.23
admin
Site Admin
Posts: 2814
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Insert values from one form to another one

Unread post by admin »

.
Locked