
Copy to Clibboard button
Can I create a button to select the contents of a field and copy them to Clipboard? (In FM Pro that was v straightforward)
-
No, as soon as there is a single quote in the data to copy it does not work ;-(
For the moment, I will be able to use this "Copy" command for a case that I use frequently: the consultation of a list of YouTube formats in the Terminal application with Youtube-dl under MacOS.
Thanks to Sean and Hans for their contributions.
Example of use in Ninox:
https://youtu.be/qCRklTpymh0 -
Hi Eric, This version allows for the ' character...
html("<button onclick='copyToClipboard(""" + replace(FieldToCopy, "'", "%27") + """)'>Copy to clipboard</button>
<script>
function copyToClipboard(str) {
var el = document.createElement('textarea');
el.value = str.replace(/%27/g, '\'');
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
</script>")
-
Hi,
Just to share some adjustments to the script I had to do to make it work for a multi-line field:
let size := length(formatJSON('My Special Field')) - 1;
let variable := substring(formatJSON('My Special Field'), 1, size);
html("<strong><button onclick='copyToClipboard(""" + variable + """)'>COPY TO CLIPBOARD</button></strong>
<script>
function copyToClipboard(str) {
var el = document.createElement('textarea');
el.value = str;
el.setAttribute('readonly', '');
el.style.position = 'absolute';
el.style.left = '-9999px';
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}
</script>") -
You can also use EvalJS (experimentally) to avoid creating HTML fields.