Copy to Clipboard

Hello dear support team,

my question relates to SharePoint Online.

How can I copy the contents of a column of type "Multiple lines of text" - Enhanced rich text (Rich text with pictures, tables, and hyperlinks) - to the clipboard?

The contents of a column of the type "multiple text lines" - plain text - I get about the following code in the clipboard:

var Betreff = fd.field('Betreff').value;
//alert("Betreff: "+Betreff);

function copy2Clipboard(str) {
	ta = document.createElement('textarea');
	ta.value = str;
	document.body.appendChild(ta);
	ta.select();
	document.execCommand('copy');
	document.body.removeChild(ta);
	
};

copy2Clipboard(Betreff)

Thanks for your help.
Kind regards

Hello @RMIC,

We've found one option of copying the content from Enhanced rich text to the clipboard as HTML.

Please follow the below steps to set up:

  1. Add a Text Field in the form. Note: the field should be visible on the form.
  2. Add Custom Button in the form.
  3. Add the following script in OnClick Settings. Replace field names in the code with the internal names of the fields in the Form.
    image
fd.field('TextField').value = fd.field('MultilineTextField').value;
setTimeout(function(){
	var copyText = $(fd.field('TextField').$el).find('input')[0];

	/* Select the text field */
	copyText.select(); 
	copyText.setSelectionRange(0, 99999); /*For mobile devices*/

	/* Copy the text inside the text field */
	document.execCommand("copy");

	/* Alert the copied text */
	alert("Copied the text: " + copyText.value);
}, 500);

Hello @mnikitina,

thank you for your feedback.

I have followed your instructions. The script I have inserted on a display.

Unfortunately I get an error "copyText is undefined":

Where is the mistake?

Thanks for your help.
Kind regards

@RMIC,

Are using the code in Button OnClick or on the form load?

Could you please send me the screenshot of the window with the code to double-check the typos.

Hello @mnikitina,

our customer has now switched to column of the type "multiple text lines" - plain text.
With this column setting, copying works very well.

Thanks for your help!

1 Like

Any input on how I might modify this example to copy the contents of the SharePoint 'Title' field to the clipboard? I was not able to alter this to meet this different need. Thanks!

Hello @Drew_Brown,

Welcome to Plumsail Community!

You can add a custom button to the form and use this code to copy the content from the Title field:

var copyText = $(fd.field('Title').$el).find('input')[0];

/* Select the text field */
copyText.select(); 
copyText.setSelectionRange(0, 99999); /*For mobile devices*/

/* Copy the text inside the text field */
document.execCommand("copy");

/* Alert the copied text */
alert("Copied the text: " + copyText.value);

image

This works great!
Now if you don't mind I'll see if we can add another wrinkle. In this case we are looking at the Edit form but the title field has been disabled. The line copyText.select(); doesn't work since it can't select the disabled text.
The alert on the copyText.value does work. Any thoughts?

Dear @Drew_Brown,
How exactly was the field disabled? Did you disable it with JS code, like this?
fd.field('Title').disabled = true;

Or did you set it to read-only state in editor?
image