Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Button to clone records in the subform
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Button to clone records in the subform
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.
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Re: Button to clone records in the subform
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...
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...
-
- Posts: 42
- Joined: Sat Jul 18, 2015 8:04 pm
- Has thanked: 3 times
Re: Button to clone records in the subform
Hi,
Try this...
Put this on the onclick event of your button. as this...
and put this in the JS section of the Form...
Steven
Try this...
Put this on the onclick event of your button. as this...
Code: Select all
cloneMe(this.id)
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.
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Re: Button to clone records in the subform
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.
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.
-
- 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
Do the fields that revert to a blank state belong to the category of text fields, lookup fields, or any other type?
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Re: Button to clone records in the subform
calida82,
Can you give us a couple of screenshots of your Subform?
Steven
Can you give us a couple of screenshots of your Subform?
Steven
A short post is a good post.
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Re: Button to clone records in the subform
You do not have the required permissions to view the files attached to this post.
-
- Posts: 58
- Joined: Mon Sep 09, 2019 8:20 am
Re: Button to clone records in the subform
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);
You do not have the required permissions to view the files attached to this post.