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)

43 replies

null
    • Retraité
    • Eric_Plet
    • 3 yrs 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

    • Sean
    • 3 yrs 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>")

    • Retraité
    • Eric_Plet
    • 3 yrs ago
    • Reported - view

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

    • englishatnoil
    • 3 yrs ago
    • Reported - view

    Thanks a lot ¡¡¡

    • eandloldham
    • 2 yrs ago
    • Reported - view

    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?

    • Sean
    • 2 yrs ago
    • Reported - view

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

     

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

    • eandloldham
    • 2 yrs ago
    • Reported - view

    Works perfectly!  Thanks so much, Sean.

    • niccuc
    • 2 yrs ago
    • Reported - view

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

    • niccuc
    • 2 yrs ago
    • Reported - view

    *word

    • Sean
    • 2 yrs ago
    • Reported - view

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

    • niccuc
    • 2 yrs 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)

    • Sean
    • 2 yrs 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.

    • Max_Kondor
    • 2 yrs ago
    • Reported - view

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

    • Hans_van_den_Herik
    • 2 yrs ago
    • Reported - view

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

    • Max_Kondor
    • 2 yrs ago
    • Reported - view

    Thank you Sean, I will try this

    • Julien.1
    • 1 yr ago
    • Reported - view

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

    Best Regards,

    • danieldavidserrano
    • 1 yr ago
    • Reported - view

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

    • Jacques_TUR
    • 1 yr ago
    • Reported - view

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

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 43Replies
  • 6689Views
  • 5 Following