You are viewing limited content. For full access, please sign in.

Question

Question

Copying to clipboard using Laserfiche Forms Modern Designer

asked on April 22

I have JavaScript in one of my Classic Designer forms that will copy the value of one of the fields to the user's clipboard on page load:

/* Copies Field2 text to clipboard upon page load */
$(document).ready(function(){
  var text = document.getElementById("Field2").textContent;
  navigator.clipboard.writeText(text).then(() => {
    console.log('Content copied to clipboard');
    /* Resolved - text copied to clipboard successfully */
  },() => {
    console.error('Failed to copy');
    /* Rejected - text failed to copy to the clipboard */
  });
});

This same code does not work in the Modern Designer. I've tried adjusting it for the Modern Designer as follows:

/* Copies Field2 text to clipboard upon page load */
$(document).ready(function(){
  var text = LFForm.getFieldValues({fieldId: 2});
  navigator.clipboard.writeText(text).then(() => {
    console.log('Content copied to clipboard');
    /* Resolved - text copied to clipboard successfully */
  },() => {
    console.error('Failed to copy');
    /* Rejected - text failed to copy to the clipboard */
  });
});

However, this does not work. Does the Modern Designer JavaScript support `navigator.clipboard.writeText()`? If not, is there any other supported way to do this?

0 0

Replies

replied on April 24

Hi Kevin,

I don't think modern form supports such javascript codes.

0 0
replied on April 26

You don't need to run $(document).ready(function(){ on the new designer by the way.

But as Zhiyong mentioned, this is probably not going to work.

The navigator functionality is based on having direct access to the structure of the document/form/page itself, and all custom Javascript in the new designer runs within a sandboxed iFrame that doesn't have that direct access.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.