Add/duplicate repeater item with button click

Hi, first post!

I have very little coding experience so apologies for any lack of clarity.

[EDIT: a simpler way of framing the question is that I want to replicate the “Manage Items > Duplicate” repeater function with a button]

I’m writing an order form within a repeater so that the user can add as many fields as they need. I’m populating the cascading form options from .js files, and intend to write the resulting data to a database.

The form is populating, and the dropdown lists are functioning independently between repeater items- I just need to let the user add additional repeater items. You can see two repeated rows in the attached image:

My code so far looks like this:

import {sheetSizes, rollSizes} from ‘public/sizes’;
import {papertype} from ‘public/papertypes’;

$w.onReady( function () {
$w(“#formatddl”).onChange( (event) => {
let $item = $;
if ($item(‘#formatddl’).value === ‘Sheet’) {
$item(‘#papersizeddl’).options = sheetSizes;
$item(‘#papersizeddl’).placeholder = ‘Select a sheet size’;
else if ($item(‘#formatddl’).value === ‘Roll’) {
$item(‘#papersizeddl’).options = rollSizes;
$item(‘#papersizeddl’).placeholder = ‘Select a roll print length’;
else {
$item(‘#papersizeddl’).value = ‘’;
$item(‘#papersizeddl’).onChange(() => {
$item(‘#papertypeddl’).options = papertype;
$item(‘#papertypeddl’).placeholder = ‘Select a paper’;
} );

} );
} );

I want to have the ‘add another print’ button add another line to the repeater , but can’t see any way to do this. I assume that i’m going to start with

$w(“#addprintbutton”).onClick( () => {
…But that’s as far as I can get.

i’ve read over the $w.repeater reference page, and the closest example that i can see is the “Set a repeater’s data and add new data on a button click”- but this doesn’t seem to be applicable to my case… My understanding isn’t great though.

Any help would be greatly appreciated! i’ve exhausted all my google-fu :frowning: