Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

duplicate / clone a subform row

Questions related to using nuBuilder Forte.
Post Reply
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

duplicate / clone a subform row

Unread post 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?
kev1n
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

Unread post by kev1n »

Here you go:

Image

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)
3. Add an afterinsertrow event to the Subform with this JavaScript:

Code: Select all

subFormAfterInserRow()
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();
}
marc
Posts: 92
Joined: Mon May 14, 2018 3:26 pm

Re: duplicate / clone a subform row

Unread post by marc »

As always, thank you kevin!!
Post Reply