I am writing a traditional web app using OutSystems 11, and am working on a Windows 10 machine...
Hello,
I am trying to create a button that copies text from either a variable or an input textbox to the clipboard. I've done some reading, and it looks like I will need to write some javascript. It seems that the most popular way to do this involves using document.execCommand('copy'). Can someone help me figure out how to do this. I have limited javascript knowledge, and was having a hard time following other posts on the topic.
Thanks,
Ryan
I did this in Reactive, you are probably in Traditional.
It is even easier. You just need to write the Jscode on the button.
Thank you! Your demo was very clear, and was exactly what I needed.
Nuno Reis wrote:
Hello Ryan,
There are forge components available, did you try these....
https://www.outsystems.com/forge/component-overview/4820/copy-to-clipboard
https://www.outsystems.com/forge/component-overview/2964/copytoclipboard
Junaid
Hello Ryan.
You can create a simple JavaScript script.
I attached a working example.
I get the following error. I believe it is because the app I am maintaining is based on the SilkUI framework, so I don't have the 'Run Client Action' or 'JavaScript' execution box features. In my environment, It think I need to run the javascript using the extended properties of a button. Can you show me how I could do that (or suggest another way)? Thanks.
Hey Nuno, thanks for your great example.
In your example you are using the input of textboxes, how is it possible to use variables as In1.
I tried it and get the error message: Cannot read property 'select' of null.
Alex
Is there more general way of doing this? I mean f.e. copying from a variable or even from an JS input parameter instead of from input widget? I can't find any proper Outsystems JS guide so it is such a black box to me. (this didn't help me at all https://success.outsystems.com/Documentation/11/Extensibility_and_Integration/JavaScript/Extend_Your_Mobile_and_Reactive_Apps_Using_JavaScript)
I found another way to solve this by using JavaScript. In case it's useful to anyone in the future:
Create a Client Action with a mandatory input parameter TextLine. Then call the following Javascript code that also has an input parameter TextLine:
function copyTextToClipboard(text) {
if (!navigator.clipboard) {
return;
}
navigator.clipboard.writeText($parameters.TextLine);
copyTextToClipboard($parameters.TextLine)
This solved my problem. Thanks. :)
This also did it for me. Thank you!
This still works.
worked for me