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)
71 replies
-
sample text:
youtube-dl -f 251 --no-cache-dir -o '/Library/WebServer/Documents/Médiathèque/ Commodores/The Commodores Anthology/Easy (Extended Version)/Easy (Extended Version) - Album Studio - Opus 160k.%(ext)s' https://youtu.be/-_z35XZWiP4
-
The only sort-of-solution I found was this...
html("<button onclick='copyToClipboard(""" + replace(FieldToCopy, "'", "") + """)'>Copy to clipboard</button>
<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>")
If you insert the string directly it works, but it's not what you're looking for. I'm not sure how to get around it.
html("<button onclick='copyToClipboard(""youtube-dl -f 251 --no-cache-dir -o '/Library/WebServer/Documents/Médiathèque/ Commodores/The Commodores Anthology/Easy (Extended Version)/Easy (Extended Version) - Album Studio - Opus 160k.%(ext)s' https://youtu.be/-_z35XZWiP4"")'>Copy to clipboard</button>
<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>")
-
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>")
-
it works !!!
Thank you so much ;-) -
Thanks a lot ¡¡¡
-
I am able to get this formula to work on every field type except a Rich Text Field. Is there a way to use this formula to select and copy a Rich Text field?
-
Just put your Rich text field inside the
text()
function...replace(text(FieldToCopy), "'", "%27")
-
Works perfectly! Thanks so much, Sean.
-
Is there a way to copy a one world field? Thank you
-
*word
-
Yes, Bastian and Hans talk about this on page 2 of this thread.
-
Sean, it doesn“t work with one word. If in the field there are 2 words, the button copy the field content in the clipboard. If there is only one word, it doesn”t :(
(sorry for my bad English)
-
niccuc, I can“t duplicate what you describe. If there is only one word that word is copied to the clipboard in my testing. If you post the code that is in your formula field I will look at it.
-
Hey Guys, I love what you have done here, it's a pretty cool workaround. Any chance one can copy a Formula field? I have data in there that appears in text from my table in a certain way. It works great when I copy a record, but doesnt when i choose the Formula field instead of 'this'.
-
Is it possible to link the 'copy code' to a button in stead of a formula field?
-
Thank you Sean, I will try this
-
Hi,
Following all the previous messages, has this feature been developped yet, please ?Best Regards,
-
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.
-
I want to let you know that the solutions you have presented are exactly what I have been looking for for a long time. However, I have a small problem that I have not been able to solve: I cannot make the text preserve line breaks when copying it. Instead, it gets copied all together, and my desire is to copy it with the line break format. Is this possible?
Content aside
- Status Answered
-
1
Likes
- 6 mths agoLast active
- 71Replies
- 7477Views
-
10
Following