Page 2 of 2

Re: Button to clone records in the subform

Posted: Wed Aug 23, 2023 4:30 pm
by kev1n
calida82 wrote: Tue Aug 22, 2023 11:52 pm There are text fields
I also see lookup and select fields.

Re: Button to clone records in the subform

Posted: Wed Aug 23, 2023 8:41 pm
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

Re: Button to clone records in the subform

Posted: Wed Aug 23, 2023 8:47 pm
by steven
calida82,

Can you show us the code that runs after each of the Lookups?


Steven

Re: Button to clone records in the subform

Posted: Wed Aug 23, 2023 10:36 pm
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);
}

Re: Button to clone records in the subform

Posted: Wed Aug 23, 2023 10:55 pm
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!

Re: Button to clone records in the subform

Posted: Thu Aug 24, 2023 6:29 am
by steven
buy kev1n a coffee!

Re: Button to clone records in the subform

Posted: Thu Aug 24, 2023 4:23 pm
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

Re: Button to clone records in the subform

Posted: Thu Aug 24, 2023 4:33 pm
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.

Re: Button to clone records in the subform

Posted: Fri Aug 25, 2023 7:30 pm
by calida82
I'm not understanding anything anymore, now it seems to work fine without having changed anything