Posts: 50
Threads: 17
Joined: Mar 2018
Reputation:
3
Location: Cincinnati, OH
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.
Posts: 46
Threads: 19
Joined: Mar 2018
Reputation:
3
Location: US
04-23-2018, 04:06 AM
(This post was last modified: 04-23-2018, 04:06 AM by mhammady.)
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
Posts: 226
Threads: 4
Joined: Mar 2018
Reputation:
22
(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
Posts: 50
Threads: 17
Joined: Mar 2018
Reputation:
3
Location: Cincinnati, OH
04-23-2018, 02:20 PM
(This post was last modified: 04-23-2018, 06:05 PM by cpstevenc.)
(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.
Posts: 1,136
Threads: 37
Joined: Mar 2018
Reputation:
30
Location: Limassol, Cyprus
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.
Posts: 50
Threads: 17
Joined: Mar 2018
Reputation:
3
Location: Cincinnati, OH
(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.
Posts: 226
Threads: 4
Joined: Mar 2018
Reputation:
22
04-23-2018, 10:41 PM
(This post was last modified: 04-24-2018, 12:23 AM by DanBarclay.)
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
Posts: 288
Threads: 0
Joined: Mar 2018
Reputation:
29
Location: Franca-São Paulo-Brasil
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;
Posts: 50
Threads: 17
Joined: Mar 2018
Reputation:
3
Location: Cincinnati, OH
04-24-2018, 08:49 PM
(This post was last modified: 04-24-2018, 08:50 PM by cpstevenc.)
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?
Posts: 288
Threads: 0
Joined: Mar 2018
Reputation:
29
Location: Franca-São Paulo-Brasil
Good to know. Try focus() before select().
Code: LBL_NUMBERTEXTIWCL.focus();
LBL_NUMBERTEXTIWCL.select();
|