0

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)

43replies Oldest first
  • Oldest first
  • Newest first
  • Active threads
  • Popular
    • Eric Plet
    • Retraité
    • Eric_Plet
    • 1 yr ago
    • Reported - view

    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

    Like
    • Sean
    • Sean
    • 1 yr ago
    • Reported - view

    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>")

    Like
    • Eric Plet
    • Retraité
    • Eric_Plet
    • 1 yr ago
    • Reported - view

    it works !!!
    Thank you so much ;-)

    Like
  • Thanks a lot ¡¡¡

    Like
  • 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?

    Like
    • Sean
    • Sean
    • 1 yr ago
    • Reported - view

    Just put your Rich text field inside the text() function...

     

    replace(text(FieldToCopy), "'", "%27")

    Like
  • Works perfectly!  Thanks so much, Sean.

    Like
    • niccuc
    • niccuc
    • 1 yr ago
    • Reported - view

    Is there a way to copy a one world field? Thank you

    Like
    • niccuc
    • niccuc
    • 1 yr ago
    • Reported - view

    *word

    Like
    • Sean
    • Sean
    • 1 yr ago
    • Reported - view

    Yes, Bastian and Hans talk about this on page 2 of this thread.

    Like
    • niccuc
    • niccuc
    • 1 yr ago
    • Reported - view

    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)

    Like
    • Sean
    • Sean
    • 1 yr ago
    • Reported - view

    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.

    Like
  • 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'.

    Like
  • Is it possible to link the 'copy code' to a button in stead of a formula field?

    Like
  • Thank you Sean, I will try this

    Like
    • Julien
    • Julien.1
    • 4 mths ago
    • Reported - view

    Hi,
    Following all the previous messages, has this feature been developped yet, please ?

    Best Regards,

    Like
  • 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>")

    Like 1
  • You can also use EvalJS (experimentally) to avoid creating HTML fields.

    Like
Like Follow
  • Status Answered
  • 3 mths agoLast active
  • 43Replies
  • 6293Views
  • 5 Following