Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Copy to clipboard?
#1
Using 14.2.7 with Tokyo Update 3 , HTTPS enabled.

I have a TIWLabel , that uses RawText = true, which for now is named ( and friendly name) lbl_NumberText

I want to be able to copy the text inside this to the clipboard.

I already know this is tricky in itself, depending on Browser... browser version... http vs https.

Using this as an example @ https://www.w3schools.com/howto/howto_js...pboard.asp

I use the onClick ScriptEvent on a button do just do the javascript code


Code:
var copyText = document.getElementById("lbl_NumberText");
    copyText.select();
    document.execCommand("Copy");
    alert("Copied the text: " + copyText.value);

This appears to not work as it never gets to the "alert" section .... I assume the script code is aborting as I am sure "lbl_NumberText" for getElementById is not quite correct.
Reply
#2
How do you call this script to make sure it is executed? Also, the label name would be in uppercase if I'm not mistaken. Did you debug your code in the browser?

Mohamed
Reply
#3
(04-23-2018, 03:22 AM)cpstevenc Wrote: Using 14.2.7 with Tokyo Update 3 , HTTPS enabled.

I have a TIWLabel , that uses RawText = true, which for now is named ( and friendly name) lbl_NumberText

I want to be able to copy the text inside this to the clipboard.

I already know this is tricky in itself, depending on Browser... browser version... http vs https.

Using this as an example @ https://www.w3schools.com/howto/howto_js...pboard.asp

I use the onClick ScriptEvent on a button do just do the javascript code


Code:
var copyText = document.getElementById("lbl_NumberText");
    copyText.select();
    document.execCommand("Copy");
    alert("Copied the text: " + copyText.value);

This appears to not work as it never gets to the "alert" section .... I assume the script code is aborting as I am sure "lbl_NumberText" for getElementById is not quite correct.

Instead of the .FriendlyName, try using .Name.

The control id is what you're looking for.  When I look at the DOM, that shows .Name in the id.

Dan
Reply
#4
(04-23-2018, 04:06 AM)mhammady Wrote: How do you call this script to make sure it is executed? Also, the label name would be in uppercase if I'm not mistaken. Did you debug your code in the browser?

Mohamed

I do the javascript in ScriptEvents , for the onClick ....

If I do just a simple alert call, that executes, so I know javascript is running via this method.

(04-23-2018, 04:06 AM)DanBarclay Wrote:
(04-23-2018, 03:22 AM)cpstevenc Wrote: Using 14.2.7 with Tokyo Update 3 , HTTPS enabled.

I have a TIWLabel , that uses RawText = true, which for now is named ( and friendly name) lbl_NumberText

I want to be able to copy the text inside this to the clipboard.

I already know this is tricky in itself, depending on Browser... browser version... http vs https.

Using this as an example @ https://www.w3schools.com/howto/howto_js...pboard.asp

I use the onClick ScriptEvent on a button do just do the javascript code


Code:
var copyText = document.getElementById("lbl_NumberText");
    copyText.select();
    document.execCommand("Copy");
    alert("Copied the text: " + copyText.value);

This appears to not work as it never gets to the "alert" section .... I assume the script code is aborting as I am sure "lbl_NumberText" for getElementById is not quite correct.

Instead of the .FriendlyName, try using .Name.

The control id is what you're looking for.  When I look at the DOM, that shows .Name in the id.

Dan

"LBL_NUMBERTEXTFRAME_STRONGS"

Is what I see looking at the DOM via Chrome.

This is in a FRAME ... and this is in "Tframe_Strongs" , so assume where STRONGS is coming from on that part.

I tried that already last night but it doesn't seem to work.

I changed up the javascript to do a try / catch


Code:
try
{
copyText = document.getElementById("LBL_NUMBERTEXTFRAME_STRONGS");
copyText.select();
document.execCommand("Copy");
alert("Copied the text: " + copyText.value);
}
 catch(err)
{
 alert(err.message); 
}

And I get an alert from the catch , "copyText.select is not a function" 

Which I take it as, the getElementById didn't hook into anything, then the next call being select, fails.
Reply
#5
Look in the DOM to see it the name matches. JS is also case sensitive nearly everywhere. In the browser press ctrl-shift-j for dev tools.
Reply
#6
(04-23-2018, 04:49 PM)kudzu Wrote: Look in the DOM to see it the name matches. JS is also case sensitive nearly everywhere. In the browser press ctrl-shift-j for dev tools.

DOM shows "LBL_NUMBERTEXTFRAME_STRONGS" in caps like that. Or at least from what I could tell.
Reply
#7
That doesn't sound right. If your target is a TWILabel, I think you should be finding a <span> with the id as the .Name but uppercase.

As an example, when I put TIWLabel on a form, set it to RawText, with default values I get:

<span class="IWLABEL3CSS" id="IWLABEL3">The label contents</span>

[edit] In addition to the name/id issue, it appears span doesn't support .select. It looks like there are some workarounds:
https://stackoverflow.com/questions/1145...n-on-click

[edit] Actually, the name you posted does look correct. If you put a control on a frame, the frame "decorates" the control name in order to avoid name collisions in the html. I do this on custom controls I've written but had never looked at regular frames. They do this as well by adding the frame name at the end of the control name.

Dan
Reply
#8
You have to use componente name (in UPPERCASE) plus IWCL directly, try:

Code:
LBL_NUMBERTEXTIWCL.select();
document.execCommand("Copy");
alert("Copied the text: " + LBL_NUMBERTEXTIWCL.value);
return true;
Reply
#9
Some progress...

Using JNPSoftware's solution, it works, but ONLY if I change the IWLabel to a IWMemo.

Reason I used IWLabel was due to HTML codes ( bolding, hrefs, ect ) that needed to be displayed. With IWMemo it shows my html tags, does not
let the formatting happen.

So "almost" there... either IWLabel somehow has to be used differently to "select" the text? or IWMemo or equivalent needed to show text
and HTML formatting.

MAYBE A hidden/visible=false IWMemo box to store the raw text in it to copy from may work?
Reply
#10
Good to know. Try focus() before select().

Code:
LBL_NUMBERTEXTIWCL.focus();
LBL_NUMBERTEXTIWCL.select();
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)