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.
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 »

calida82 wrote: Tue Aug 22, 2023 11:52 pm There are text fields
I also see lookup and select fields.
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Button to clone records in the subform

Unread post by calida82 »

I understood you meant only the fields that weren't being cloned. Excuse me
yes the lookup fields don't have fields connected to the db I use them with php functions to fill in the Brand and Model Size fields. Even the field the select MM field is not connected to the db but has defined values ​​while the position field is connected with a foreign key to another table.
all these fields, however, a few days ago with the clone button were filled in regularly. only the measurement field and the model field were not filled in, or rather they were filled in and then immediately emptied. and cloning an unsaved record copied themselves completely. now no longer
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 show us the code that runs after each of the Lookups?


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 »

first lookup

Code: Select all

$l = nuLookupRecord();
nuSetFormValue("pne_misura", $l->mis_misura);
second lookup

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);
}
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Button to clone records in the subform

Unread post by calida82 »

I think I solved it, or at least for the moment it works, I eliminated the 2 lookup objects found in columns 1 and 3 from the copy. this way it seems to work

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 = 2 ; i < s.length-1 ; i++){                          //-- loop from THIRD fields
        
          if(i != 3){                                                         // to the second lookup column I do nothing
             nuSetValue(b + s[i], d[i]);
             
          }      
    }
    
}
thanks for your help!
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 »

buy kev1n a coffee!
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 »

steven wrote: Thu Aug 24, 2023 6:29 am buy kev1n a coffee!
I will gladly do it. but I sang victory too soon. there is another little problem. now the button works perfectly, but when i save the last cloned row it is not saved
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 »

calida82 wrote: Thu Aug 24, 2023 4:23 pm now the button works perfectly, but when i save the last cloned row it is not saved
This is strange. Since nuSetValue() marks those fields as "edited" these changes ought to be saved to the database.
calida82
Posts: 58
Joined: Mon Sep 09, 2019 8:20 am

Re: Button to clone records in the subform

Unread post by calida82 »

I'm not understanding anything anymore, now it seems to work fine without having changed anything
Post Reply