
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)
-
Max, I don't know which version you are using, but this one worked for me...
html("<button onclick='copyToClipboard(""" + 'Formula Field' + """)'>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>")
Hans, Not that I'm aware of, but you can use "style" to modify the appearance of the button. Search on style for the HTML button tag.
-
Hello, I found this solution online and adapted it to work in Ninox. The code goes in Formula field and it copies the current record information to the clipboard...
html("<button onclick='copyToClipboard(""" + concat(this) + """)'>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>")
-
Bingo! That is the perfect solution.
Just in case anyone is unclear about how to make this work...
Use the "Fx Formula" option to add a formula field to your record. (I.e. not a button field - tried that, didn't work)
Add the following code where the Formula code goes:
html("<button onclick='copyToClipboard(""" + concat('Project Name') + """)'>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>")Where I have:
'Project Name'
in concat('Project Name')
is where you will want to put the name of the field you want to copy. If you want to copy the whole record, simply add the word
this
as in contcat(this)
...and you are done, and Ninox has one less development item on their list.
-
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>")