1

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

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

    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

    • Sean
    • 3 yrs ago
    • Reported - view

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

    • 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
    • 3 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
    • 3 yrs ago
    • Reported - view

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

     

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

    • eandloldham
    • 3 yrs ago
    • Reported - view

    Works perfectly!  Thanks so much, Sean.

    • niccuc
    • 3 yrs ago
    • Reported - view

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

    • niccuc
    • 3 yrs ago
    • Reported - view

    *word

    • Sean
    • 3 yrs ago
    • Reported - view

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

    • niccuc
    • 3 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
    • 3 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
    • 3 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
    • 3 yrs ago
    • Reported - view

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

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

    • Ninox developper
    • Jacques_TUR
    • 1 yr ago
    • Reported - view

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

      • gold_cat
      • 4 mths ago
      • Reported - view

      I also need to copy text within a specified field. Are there any new methods? Thanks.

      • Ninox developper
      • Jacques_TUR
      • 4 mths ago
      • Reported - view

      Hello and sorry for the long delay in responding. I've been quite busy lately. I created a small application with one button to copy and another to paste. I am using a very simple JavaScript for that which I implement with the Ninext syntax #{...}#.

      The paste function works for all browsers.
      Unfortunately, the paste function does not work for Firefox.

      • gold_cat
      • 4 mths ago
      • Reported - view

      You are always professional and helpful. I appreciate it.

       

    • manuel_cha2
    • 2 mths ago
    • Reported - view

    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?

      • Sean
      • 2 mths ago
      • Reported - view

       

      Try replacing textarea with pre. I can’t test it right now.

Content aside

  • Status Answered
  • 1 Likes
  • 2 wk agoLast active
  • 71Replies
  • 7267Views
  • 10 Following