`copyToClipboard()` Not Working Inside a Repeater - No Error Messages

Hello,

I am developing a feature on a website that allows users to copy text from an element within a repeater by clicking a button. Despite using the wixWindow.copyToClipboard() method and confirming that there are no errors shown in the console, the button doesn’t seem to function as expected — nothing happens when it is clicked.

Here’s the code I am using:

import wixWindow from ‘wix-window’;
import wixData from ‘wix-data’;

$w.onReady(function () {
$w(“#repeaterId”).forEachItem(($item, itemData, index) => {
$item(“#buttonId”).onClick(() => {
const textToCopy = $item(“#textId”).text; // Text to be copied
wixWindow.copyToClipboard(textToCopy)
.then(() => {
console.log(“Text copied successfully!”);
$item(“#buttonId”).label = “Copied”; // Feedback by changing the button label
})
.catch((err) => {
console.error("Failed to copy text: ", err);
});
});
});
});

Details:

  • I have verified that all IDs are correct and the respective elements are present in the Editor.
  • The text that should be copied is correctly displayed in the text element (#textId) of the repeater.
  • There are no error messages in the console, neither in the .then() nor in the .catch().

What I am trying to achieve:
I want the button click to copy the text displayed in the repeater to the clipboard. The user should receive feedback through the button label change (“Copied”) indicating that the text has been copied.

Could someone please help to understand why the copyToClipboard() function is not being triggered, or what I might be overlooking?

Thank you in advance for your support!
.

Try onItemReady instead of forEachItem

$w(“#repeaterId”).onItemReady(($item, itemData, index) => {

Thank you. Works perfect.