Hello Everybody,
Just found this thread - is it possible to update it for collection? Saw the thread about copy fields from one row of the collection to another, however this answer has a clone() action, can we do it on collection?
Thank you,
Update:
after some digging around put pieces together, looks like it works for collections, can anybody validate?
function addDuplicateButton() {
$('<span class="dup">Copy</span>').appendTo('ul.rpx');
}
addDuplicateButton()
$(document).on('click','.dup', function(event) {
// jQuery does not clone dynamic state of select
var selectedValue = $(event.target).closest('div.form-q').find('.selectField').find($('select[id^=Field20]')).val()
$('.cf-collection-delete').show();
$(event.target).closest('div.form-q').clone().appendTo($(event.target).closest('.cf-collection'));
$('.selectField select').val(selectedValue);
return;
});
Update two:
The code is working in general however it breaks Forms Field rules and formulas - they don't work on a copied row. Changed the code to use Add button instead. Again, calling for the experts to validate.
Thank you,
$(document).on('click','.dup', function(event) { // Copy row
var currIndex = $(event.target).closest('div.form-q').find('.lineID').find($('input[id^=Field156]')).val()-1;
var rowFields = new Array();
// return current row
$('#q16 .kx-repeatable > div').filter( function (ind) {
return ind === currIndex;
}).find("[vo]").each( function (ind) { // save each field
rowFields[ind] = $(this).val();
});
$('.cf-collection-append').click();
// get last row
currIndex = $('#q16 .kx-repeatable > div').length - 1;
$('#q16 .kx-repeatable > div').filter( function (ind) {
return ind === currIndex;
}).find("[vo]").each( function (ind) { // copy each field with value but first
if ((rowFields[ind]!=null) && (ind != 0)) {
$(this).val(rowFields[ind]).change();
}
});
return;
});