Welcome to the nuBuilder Forums!

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

Button to clone records in the subform

Questions related to customising nuBuilder Forte with JavaScript or PHP.
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Button to clone records in the subform

Unread post by calida82 »

I'm creating a small application for managing summer/winter tire depots. Since in most cases the cars almost always have the same sizes and the same tire brands and models, I would like to add a button that allows me to copy a line without having to type it again. but i can't figure out how to fetch data from current row
You do not have the required permissions to view the files attached to this post.
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Button to clone records in the subform

Unread post by calida82 »

i found
this
but copy the entire row only if the row to be copied hasn't been saved yet.
if the row has already been saved, copy only some fields, others remain empty...
saultpastor
Posts: 42
Joined: Sat Jul 18, 2015 8:04 pm
Has thanked: 3 times

Re: Button to clone records in the subform

Unread post by saultpastor »

I'm having the same problem...
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: Button to clone records in the subform

Unread post by steven »

Hi,

Try this...

Put this on the onclick event of your button. as this...

Code: Select all

cloneMe(this.id)
and put this in the JS section of the Form...

Code: Select all


function cloneMe(id){

    var f = $('#' + id).attr('data-nu-form');
    var o = nuSubformObject(f);
    var p = $('#' + id).attr('data-nu-prefix');
    var r = Number(p.substr(-3));                                   //-- get the row number of the button clicked
    var b = f + nuPad3(o.rows.length - 1);                          //-- bottom empty row
    var d = o.rows[r];                                              //-- get values from that row
    var s = o.fields;                                               //-- get destination fieldnames for those values
    
    for(var i = 1 ; i < s.length-1 ; i++){                          //-- loop from second field to second to last field (ignoring ID and nuDelete)
        nuSetValue(b + s[i], d[i])        
    }
    
}


Steven
A short post is a good post.
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Button to clone records in the subform

Unread post by calida82 »

hi thanks for your input, i tried your code but the result didn't change.
when I press the button the new line appears and for an instant all the fields are filled in, but then two fields go back to being empty... the same thing happened with the other code too.
kev1n
nuBuilder Team
Posts: 4292
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Button to clone records in the subform

Unread post by kev1n »

Do the fields that revert to a blank state belong to the category of text fields, lookup fields, or any other type?
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Button to clone records in the subform

Unread post by calida82 »

There are text fields
steven
Posts: 369
Joined: Mon Jun 15, 2009 10:03 am
Has thanked: 52 times
Been thanked: 52 times

Re: Button to clone records in the subform

Unread post by steven »

calida82,

Can you give us a couple of screenshots of your Subform?


Steven
A short post is a good post.
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Button to clone records in the subform

Unread post by calida82 »

sc1.png
You do not have the required permissions to view the files attached to this post.
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Button to clone records in the subform

Unread post by calida82 »

sc1.png
sc1.png
Here are my screens.
the Misura, Marca, and Modello fields are simple text fields that are filled in using the after browse lookup function.

Code: Select all

$lu = nuLookupRecord();
nuSetFormValue("pne_modello", $lu->mod_modello);
$sql = "SELECT * FROM t_marche WHERE t_marche.mar_id = ?";
$risultato = nuRunQuery($sql,array($lu->mod_id_marca));
if (db_num_rows($risultato) == 1) {
    $r  = db_fetch_object($risultato);
    nuDebug($r);
    nuSetFormValue("pne_marca", $r->mar_marca);
}

Code: Select all

$l = nuLookupRecord();
nuSetFormValue("pne_misura", $l->mis_misura);
In the past days the fields that were not filled in were Misura and Modello, I tried now and only the Misura field, nothing of the others, is copied. the code is still the same as days gone by
sc3.png
and it is the same for those just inserted not only for those already saved
You do not have the required permissions to view the files attached to this post.
Post Reply