Copy field contents on button click in adaptive form | Community
Skip to main content
Level 2
September 15, 2020
Solved

Copy field contents on button click in adaptive form

  • September 15, 2020
  • 3 replies
  • 1653 views

Hi all,

 

I've spent hours going in circles, trying different approaches and I'm just totally stuck. I've created an adaptive form in AEM for forms. I have a hidden text field with a text string value, and I am trying to script a button to select and copy the contents of that text field, when clicked. Then I'd like a message to pop up, confirming the text was copied.

 

Here's the method I found on W3schools:

var copyText = document.getElementById("textFieldIWantToCopy");
copyText.select();
document.execCommand("copy");
alert("Copied the text: " + copyText.value);

 

Absolutely nothing happens when I use this script. I'm still adjusting between LiveCycle Javascript and normal JavaScript, so it could be I just don't have the syntax/terms to do it right, yet.

 

Does anyone know how to make this work? Thanks so much for your help!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

workflowuserAdobe EmployeeAccepted solution
Adobe Employee
September 15, 2020
Mayank_Gandhi
Adobe Employee
Adobe Employee
September 17, 2020

@jlndev  Works for me

 

Put this on button click:

document.getElementById("guideContainer-rootPanel-basics-basics1-guidetextbox___widget").select();
document.execCommand("copy");
alert("copied");

 

In Adaptive form go to code editor and place the script. Make sure to replace "guideContainer-rootPanel-basics-basics1-guidetextbox___widget" with correct id for the text field

XIIX
September 23, 2021

Mate, I had this exact problem and the same experience of going around in circles for hours. I'm still an old-school LC Designer developer and I'm eager to get the code right. Your code helped me and I'll share mine in an effort to iterate towards a final acceptable method..

 

var copyText = document.querySelector("#input");
copyText.select( vForm.oPage.sfpControlPanel.txtVersion.rawValue );
document.execCommand("copy");

 

method source: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard

 

My efforts were substantially incomplete, but it was the first time I sought a solution outside W3schools or the XFA Scripting Reference materials so I thought I'd include it in case you can gather more breadcrumbs in search of a working solution..