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

Question

Question

Copy Text button on LF from to copy field input to clipboard

asked on July 6, 2021

Hi team,

I have a requirement where an user needs to copy a web link (in a text field) from Laserfiche forms using a copy button. I have used a combination of HTML custom button and script.

function myFunction() {
 var copyText = $('.myinput input').val();
 $('#q8').copy(); 

document.execCommand("copy");
alert('Inspection completed for :' + copyText );
}

 $('#q8').copy(); - this do not work. I have also tried copyText.select(), didnt work either.

Please let me know if anyone has come across similar requirement and a solution for the same.

Thanks in advance.

Bipin

1 0

Replies

replied on July 6, 2021 Show version history

A couple of things:

  1. jQuery selectors return an array, but the copy function requires a single object
  2. The copy function works with an input field, not a string (i.e., the object, not the .val() result)
  3. Your #q8 selector is targeting the parent, not the input

 

Here's an example using class selectors

  $('#copyBtn').on('click',function(){
    $('.myinput input')[0].select();
    
    document.execCommand('copy');
  });

The [0] piece uses indexing to retrieve only a single object so the select() method will work.

That will be the input itself, which will then work with the copy command.

If you want to use the id selector, then it wouldn't be #q8, but if the parent is #q8 then the input (assuming it's not in a collection) would be #Field8

1 0
replied on July 7, 2021

Hi Jason,

Thank you for the response.

function myFunction() {
  //  var copyText = $('.myinput input').val();
    $('.myinput input')[0].select();
    document.execCommand('copy');
  //  alert('Inspection completed for :'+copyText );
}

The above got me going. I guess "The [0] piece uses indexing to retrieve only a single object so the select() method will work." did the trick.

 

Thank you.

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

Sign in to reply to this post.