Skip to main content
Question

Working Copy to Clipboard Button

  • July 15, 2019
  • 0 replies
  • 972 views

I've created a button to copy the content of a field to the clipboard that I thought would be useful to others.

It copies the content of the field and then shows an alert that confirms what was copied.

I've tested it with Chrome and Firefox which works, Edge did not. 

I used a Vibrant button, which allows me to put it into a Rich Text field with other buttons, instead of a Formula URL field.  It will work with the URL field as well if you remove the button code. 

Hope this helps.

Dana

var text CB= URLEncode([Some Field]);
var text Alert= URLEncode([Some Field] & " Was Copied to the Clipboard");
"<a class='Vibrant Success' style=\"border:0px solid green; background-color:green; text-align: center;\"href=" &
"javascript:{" & "navigator.clipboard.writeText('" & $CB & "').then(function(){" & "},function(){" & "});" & "alert('" & $Alert & "');" & "};" & ">Copy to the Clipboard</a>"


This topic has been closed for replies.

Awesome contribution @Dana!! If I could add 1 small enhancement idea, in order to give it a more quickbase feel:

var text CB= URLEncode([Activity Details]);
var text Alert= URLEncode("Activity Details" & " were Copied to the Clipboard");
"<a class='Vibrant Success' style=\"border:0px solid green; background-color:green; text-align: center;\"href=" &  
    "javascript:{" &
"navigator.clipboard.writeText('" & $CB & "').then(function(){" &
"},function(){" &
"});" &
    //"alert('" & $Alert & "');" &
    "$.jGrowl('" & $Alert & "');" &
"};" &
    ">Copy to the Clipboard</a>"

Replacing your "alert" with "$.jgrowl" will throw the native QB growl message which is a little prettier than a javascript alert. FYI to everyone else -- this will work for any situation where you are using alerts in this fashion.


  • Quickbase Alumni
  • July 16, 2019
Thanks for this. It looks much simpler to implement than the other solutions posted in the past. You could just use this as a button and not bother with IOL or any of that which is definitely my preference.

I figure it cannot hurt to consolidate data so thought I would put a link to another copy to clipboard button. Just in case someone is searching and wants to see everything that is out there. There have been some complaints that this is no longer working but maybe it can inspire someone to fix the issues or add some features to yours even.

https://community.quickbase.com/quickbase/topics/i-got-my-clipboard

Is there a limit to what the clipboard write function can copy? It worked on little things but not the output of a massive formula rich text field.

@Dana...you are correct in that a URL cannot be more than a certain length however we are merely forming an href here via javascript so we are not bound by that limit per-se. I just tested with strings in the 50-60K range and it works just fine. @Jordan...how big is your string? Can you copy/paste just using your mouse? You can get the string length here: https://www.lettercount.com/

MattMakris
Forum|alt.badge.img+7
  • Quickbase Alumni
  • February 18, 2022
I'm getting an error about it having javascript:

Only text, Quickbase-accepted functions, fields, variables, and certain HTML tags are allowed in this field. JavaScript is not supported.

Is there a workaround?

------------------------------
Matt Makris
------------------------------