Page 1 of 1
duplicate / clone a subform row
Posted: Tue Apr 28, 2020 11:55 am
by marc
Hi,
I can clone a form with the clone button - Is there a function to clone/duplicate a subform row? maybe with js?
Re: duplicate / clone a subform row
Posted: Fri May 01, 2020 4:31 am
by kev1n
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,
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();
}
Re: duplicate / clone a subform row
Posted: Tue May 05, 2020 3:44 pm
by marc
As always, thank you kevin!!