Page 1 of 2
Button to clone records in the subform
Posted: Wed Aug 16, 2023 4:04 pm
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
Re: Button to clone records in the subform
Posted: Wed Aug 16, 2023 5:43 pm
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...
Re: Button to clone records in the subform
Posted: Thu Aug 17, 2023 10:00 pm
by saultpastor
I'm having the same problem...
Re: Button to clone records in the subform
Posted: Mon Aug 21, 2023 9:24 pm
by steven
Hi,
Try this...
Put this on the onclick event of your button. as this...
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
Re: Button to clone records in the subform
Posted: Mon Aug 21, 2023 10:47 pm
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.
Re: Button to clone records in the subform
Posted: Mon Aug 21, 2023 10:53 pm
by kev1n
Do the fields that revert to a blank state belong to the category of text fields, lookup fields, or any other type?
Re: Button to clone records in the subform
Posted: Tue Aug 22, 2023 11:52 pm
by calida82
There are text fields
Re: Button to clone records in the subform
Posted: Wed Aug 23, 2023 1:36 am
by steven
calida82,
Can you give us a couple of screenshots of your Subform?
Steven
Re: Button to clone records in the subform
Posted: Wed Aug 23, 2023 2:13 pm
by calida82
Re: Button to clone records in the subform
Posted: Wed Aug 23, 2023 2:24 pm
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