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

    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.

      • szormpas
      • 1 yr ago
      • Reported - view

        Hi, I have just added a "Copy to Clipboard" button in my dashboard, and I can confirm that the code still works perfectly. For the sake of completeness, I would like to share the entire code with button styling options. Thank you for your valuable contribution, Sean!

      html("<html lang='en'>
      <head>
        <meta charset='UTF-8'>
        <meta name='viewport' content='width=device-width, initial-scale=1.0'>
        <style>
          /* Define the style for the button */
          .custom-button {
            color: rgb(86, 110, 177); /* Text color */
            background-color: white;  /* Background color */
            padding: 3px 10px;       /* Padding for better appearance */
            border: 1px solid rgb(86, 110, 177); /* Rounded border with text color */
            border-radius: 5px;       /* Add rounded corners */
            cursor: pointer;         /* Change cursor on hover */
            font-weight: bold;       /* Make the text bold */
          }
        </style>
      </head>
      <body>
      <button class='custom-button'; onclick='copyToClipboard(""" +
      INSERT_HERE_YOUR_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>
      </body>
      </html>")
      
      • Sean
      • 1 yr ago
      • Reported - view

       Thank you for sharing and I'm glad you found it useful.

    • Birger_H
    • 6 yrs ago
    • Reported - view

    Copy to Clipboard is not yet available :-(

    Birger

    • Personal
    • Art
    • 5 yrs ago
    • Reported - view

    Sad to see it's not available yet. I would use this.

    • CentralGamer
    • 5 yrs ago
    • Reported - view

    Me too!

    • james_deraps
    • 4 yrs ago
    • Reported - view

    Must be add!!!

    • Karen_Estrada
    • 4 yrs ago
    • Reported - view

    ++ :-)  as well! KE

    • blickfang Internet- & Werbeagentur GmbH
    • Timo_L
    • 4 yrs ago
    • Reported - view

    need this, too!

    • majlo
    • 4 yrs ago
    • Reported - view

    :( need this, too

    • lanematthewc
    • 4 yrs ago
    • Reported - view

    I would also find this very useful. Thanks for all your work! =)

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

    need this too.

    • Kaan_Dikmen
    • 4 yrs ago
    • Reported - view

    This would be very useful to send data to Shortcuts workflows. 1+ !!!

    • Halio
    • Halio
    • 4 yrs ago
    • Reported - view

    Any update on this?

    Just to clarify, there is no way to program a button to copy the content from a field to the clipboard?

    • Sean
    • 4 yrs ago
    • Reported - view

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

    • Hans
    • 4 yrs ago
    • Reported - view

    Thanks Sean, that works! 

    Is there any way to make it focus on the contents of just one field in the record?

    • Sean
    • 4 yrs ago
    • Reported - view

    Not that I'm aware of. It is a long awaited feature request.

    • Hans
    • 4 yrs ago
    • Reported - view

    I see that. :) Looking forward to the development. 

    • Bastian Rohde Immobilien
    • Bastian_Rohde
    • 4 yrs ago
    • Reported - view

    sure that works - you just need to replace this piece here in the first line:

     concat(this) 

    I have replaced this with one column and it works.

    • Bastian Rohde Immobilien
    • Bastian_Rohde
    • 4 yrs ago
    • Reported - view

    thanks Sean for sharing - this was really helpful!

    • Hans
    • 4 yrs ago
    • Reported - view

    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.

    • Sean
    • 4 yrs ago
    • Reported - view

    Sorry, I misunderstood your question. I thought you wanted set the focus of a Ninox field. D'oh! 😬

    • hughbs
    • 4 yrs ago
    • Reported - view

    Thank you Sean and Hans, the perfect solution! And one can change the name on the button to the name of the field being copied.

    • Hans
    • 4 yrs ago
    • Reported - view

    For the record, Sean and Bastian did the heavy lifting. I'm just really good at copy paste. :)

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

    a specific character contained in the field to copy prevents this script from working: '

Content aside

  • Status Answered
  • 1 Likes
  • 8 mths agoLast active
  • 71Replies
  • 7573Views
  • 10 Following