Copy to clipboard function for repeater

using the copy to clipboard function. [copyToClipboard - Velo API Reference - Wix.com](copyToClipboard - Velo API Reference - Wix.com

the)

The function works well if its only a single box with text. But if I set the value in a repeater it does not work. The console log shows its copied but it doesn’t actually copy anything.

Sample website with code below–> https://jaosh8.wixsite.com/mysite-7/copy

Please let me know what I am doing wrong.

// For full API documentation, including code examples, visit https://wix.to/94BuAAs

import wixWindow from 'wix-window';
// ...

export function button1_click(event) {
 // Add your code for this event here: 
 let textbox = $w('#textBox1').value;

wixWindow.copyToClipboard(textbox)
  .then( () => {
      console.log("copied");
 // handle case where text was copied
  } )
  .catch( (err) => {
          console.log("not copied");
 // handle case where an error occurred
  } );
}

export function button2_click(event) {

let textbox = $w('#textBox2').value;

wixWindow.copyToClipboard(textbox)
  .then( () => {
      console.log("copied");
 // handle case where text was copied
  } )
  .catch( (err) => {
          console.log("not copied");
 // handle case where an error occurred
  } );  // Add your code for this event here: 
}

You need to scope the item if the event occurs inside a repeater.

Thanks for the suggestion. Tried to look it up and researched to make some changes to the code on the page https://jaosh8.wixsite.com/mysite-7/copy

The issue is now that it only seems to copy the last item in the repeater there is. What could I be doing wrong here?

// For full API documentation, including code examples, visit https://wix.to/94BuAAs

import wixWindow from 'wix-window';
// ...



$w.onReady( function () {

$w("#dataset1").onReady( () => {
  console.log("The dataset is ready");

  $w("#repeater1").onItemReady( ($item, itemData, index) => {
    $w("#button2").onClick( (event) => {
 
     let $item = $w.at(event.context);
     let textbox = (itemData.url);

      wixWindow.copyToClipboard(textbox)
      .then( () => {
      console.log("copied");
 // handle case where text was copied
      } )
      .catch( (err) => {
        console.log("not copied");
 // handle case where an error occurred
      } );
    } );


  } );  

} );

 
} );

Remove everything from the page’s onReady function and do this:

$w.onReady(function () {
    $w("#button2").onClick( (event) => {
        let $item = $w.at(event.context);
        wixWindow.copyToClipboard($item('#textBox2').value) //element id with $item
        .then( () => {
            console.log("copied");
        })
        .catch( (err) => {
            console.log("not copied");
        });
    });
});

@shantanukumar847 Thanks. This works