Hi,
I can clone a form with the clone button - Is there a function to clone/duplicate a subform row? maybe with js?
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.
duplicate / clone a subform row
-
- nuBuilder Team
- Posts: 4307
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 448 times
- Contact:
Re: duplicate / clone a subform row
Here you go:

1. Add a button to your Subfrom with Title Clone
2. Attach an onclick event to your button in the Custom Code Tab with the JavaScript
3. Add an afterinsertrow event to the Subform with this JavaScript:
4. Add this JavaScript to your (main) form's Custom Code field,

1. Add a button to your Subfrom with Title Clone
2. Attach an onclick event to your button in the Custom Code Tab with the JavaScript
Code: Select all
onSubformClone(event)
Code: Select all
subFormAfterInserRow()
Code: Select all
var sfId = 'Subform_Object_ID'; // <-- Replace with the Subform Object ID.
var btnCloneId = 'Clone_Button_ID'; // <-- Replace with the Button ID of the Clone Button
function getRowNumber(id) {
return $('#' + String(id)).attr('data-nu-prefix').slice(-3);
}
function onSubformClone(event) {
var id = event.target.id;
var sfId = $('#' + id).attr('data-nu-form');
var sr = nuPad3(getRowNumber(id));
var dr = nuPad3(nuSubformObject(sfId).rows.length - 1);
var obj = nuSubformObject(sfId)
for (var c = 0; c < obj.fields.length - 1; c++) {
var s = $('#' + sfId + nuPad3(sr) + obj.fields[c]);
var d = $('#' + sfId + nuPad3(dr) + obj.fields[c]);
if (s.is(':radio,:checkbox')) {
d.prop('checked', s.prop('checked')).change();
} else {
d.val(s.val()).change();
}
}
}
function hideLastCloneButton() {
var r = nuPad3(nuSubformObject(sfId).rows.length - 1);
cloneButton = st + nuPad3(r) + btnCloneId;
nuHide(cloneButton);
}
function subFormAfterInserRow() {
// Show all clone buttons
$("[id$='" + btnCloneId + "']").each(function (i, obj) {
nuShow($(this).attr('id'));
});
hideLastCloneButton();
}
if (nuFormType() == 'edit') {
hideLastCloneButton();
}
-
- Posts: 92
- Joined: Mon May 14, 2018 3:26 pm