Page 1 of 1

Insert values from one form to another one

Posted: Wed Jun 13, 2018 11:59 am
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)?

Re: Insert values from one form to another one

Posted: Thu Jun 14, 2018 12:30 am
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

Re: Insert values from one form to another one

Posted: Thu Jun 14, 2018 10:01 am
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)

Re: Insert values from one form to another one

Posted: Fri Jun 15, 2018 12:12 am
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

Re: Insert values from one form to another one

Posted: Fri Jun 15, 2018 10:23 am
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.

Re: Insert values from one form to another one

Posted: Fri Jun 15, 2018 11:44 am
by toms
You need to invoke .change() otherwise the fields will not be saved.

Code: Select all

$('#inv_phone').val(p).change();

Re: Insert values from one form to another one

Posted: Fri Jun 15, 2018 1:00 pm
by marcvander
Thanks toms, it works now. Thanks to both of you

Re: Insert values from one form to another one

Posted: Wed Jun 27, 2018 3:02 am
by admin
.