Highlighted

EventListener not working for edittext

Advocate ,
Oct 27, 2020

Copy link to clipboard

Copied

Dear friends,

I'm working with FrameMaker - and there the experts of ExtendScript gave me the hint to post in this forum. But first I want to thank members of this forum, in particular Peter Kahrel and "Jongware" for the documentation they provide - filling painful gaps in the 'official' documentation.

My problem is sketched in the title: EventListener not working for edittext.

In an edittext  users can Select All and then copy the contents of  t he object and this content can also be deleted after selection. I want to make it 'user friendly': single click into the area copies the content to the clipboard, double click deletes the contents:

find-replace-display01.png

In the following script a click/double click into the edittext area does nothing. If I write

win.eField.addEventListener ("click (detail = 1)", hClick(), false); or hDClick() then the alert is executed without any user action on the window. Whether the last parameter is true or false has no effect.

→ What is wrong with my script?

 

 

/*  on(Double)Click.jsx ====== UTF-8 ====================================
              check possibilites to act on an edittext click/doubleclick
              in ExtendScript Toolkit CC
Comment       There is no onClick (and no onDoubleClick) for edittext
              Hence appropriate event listeners must be defined
              See JavaScript Tools Guide for the eventName in 
              controlObj.addEventListener (eventName, handler[, capturePhase]);
Reference     https://stackoverflow.com/questions/39416360/set-focus-of-edit-text-in-extendscript
              https://www.youtube.com/watch?v=967C8erAN6c
History       2020-10-25
*/ ; // ==================================================================

main = function () {
var  win;

  win = new Window ("dialog", "on(Double)click", undefined, undefined);
  win.eField    = win.add ("edittext", undefined, "Text in field", undefined);
  win.btnCancel = win.add ("button", undefined, "Cancel", undefined);
  
//win.eField.active = true;
  win.eField.addEventListener ("click (detail = 1)", hClick, false);
  win.eField.addEventListener ("click (detail = 2)", hDClick, false);

  win.show ();
} //--- end main

hClick = function () {
  alert ("Click into edittext");
  $.writeln ("Click into edittext");
} //--- end hClick

hDClick = function () {
  alert ("DoubleClick into edittext");
  $.writeln ("DoubleClick into edittext");
} //--- end hDClick

main ();

 

 

Thank You for help

Klaus Daube

--- Edit ---

If i change the window type to palette then the script just runs through and I see the window only for a subsecond...

Adobe Community Professional
Correct answer by Peter Kahrel | Adobe Community Professional

You would indeed expect you could click in a text field and select all its content. But you can't. You can add an onActivate handler, but apparently ScriptUI thinks that when it has responded to onActivate, giving in to .active = true is too much of a good thing. You can add a button and do an onClick event that activates the text field, but that's not what you want.

 

edittext controls don't support click events I don't think. You'd have to use onActivate, but that doesn't work either.

 

If i change the window type to palette then the script just runs through and I see the window only for a subsecond...

 

You'd have to run the script in a target engine. Nowadays in InDesign there's no need for that when you run the script from the Scripts panel, onky when you run it straight from the ESTK. How that plays in FrameMaker I've no idea. Maybe FrameMaker (like Photoshop) doesn't support palettes.

 

P.

TOPICS
Scripting

Views

52

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

EventListener not working for edittext

Advocate ,
Oct 27, 2020

Copy link to clipboard

Copied

Dear friends,

I'm working with FrameMaker - and there the experts of ExtendScript gave me the hint to post in this forum. But first I want to thank members of this forum, in particular Peter Kahrel and "Jongware" for the documentation they provide - filling painful gaps in the 'official' documentation.

My problem is sketched in the title: EventListener not working for edittext.

In an edittext  users can Select All and then copy the contents of  t he object and this content can also be deleted after selection. I want to make it 'user friendly': single click into the area copies the content to the clipboard, double click deletes the contents:

find-replace-display01.png

In the following script a click/double click into the edittext area does nothing. If I write

win.eField.addEventListener ("click (detail = 1)", hClick(), false); or hDClick() then the alert is executed without any user action on the window. Whether the last parameter is true or false has no effect.

→ What is wrong with my script?

 

 

/*  on(Double)Click.jsx ====== UTF-8 ====================================
              check possibilites to act on an edittext click/doubleclick
              in ExtendScript Toolkit CC
Comment       There is no onClick (and no onDoubleClick) for edittext
              Hence appropriate event listeners must be defined
              See JavaScript Tools Guide for the eventName in 
              controlObj.addEventListener (eventName, handler[, capturePhase]);
Reference     https://stackoverflow.com/questions/39416360/set-focus-of-edit-text-in-extendscript
              https://www.youtube.com/watch?v=967C8erAN6c
History       2020-10-25
*/ ; // ==================================================================

main = function () {
var  win;

  win = new Window ("dialog", "on(Double)click", undefined, undefined);
  win.eField    = win.add ("edittext", undefined, "Text in field", undefined);
  win.btnCancel = win.add ("button", undefined, "Cancel", undefined);
  
//win.eField.active = true;
  win.eField.addEventListener ("click (detail = 1)", hClick, false);
  win.eField.addEventListener ("click (detail = 2)", hDClick, false);

  win.show ();
} //--- end main

hClick = function () {
  alert ("Click into edittext");
  $.writeln ("Click into edittext");
} //--- end hClick

hDClick = function () {
  alert ("DoubleClick into edittext");
  $.writeln ("DoubleClick into edittext");
} //--- end hDClick

main ();

 

 

Thank You for help

Klaus Daube

--- Edit ---

If i change the window type to palette then the script just runs through and I see the window only for a subsecond...

Adobe Community Professional
Correct answer by Peter Kahrel | Adobe Community Professional

You would indeed expect you could click in a text field and select all its content. But you can't. You can add an onActivate handler, but apparently ScriptUI thinks that when it has responded to onActivate, giving in to .active = true is too much of a good thing. You can add a button and do an onClick event that activates the text field, but that's not what you want.

 

edittext controls don't support click events I don't think. You'd have to use onActivate, but that doesn't work either.

 

If i change the window type to palette then the script just runs through and I see the window only for a subsecond...

 

You'd have to run the script in a target engine. Nowadays in InDesign there's no need for that when you run the script from the Scripts panel, onky when you run it straight from the ESTK. How that plays in FrameMaker I've no idea. Maybe FrameMaker (like Photoshop) doesn't support palettes.

 

P.

TOPICS
Scripting

Views

53

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 27, 2020 0
Adobe Community Professional ,
Oct 27, 2020

Copy link to clipboard

Copied

You would indeed expect you could click in a text field and select all its content. But you can't. You can add an onActivate handler, but apparently ScriptUI thinks that when it has responded to onActivate, giving in to .active = true is too much of a good thing. You can add a button and do an onClick event that activates the text field, but that's not what you want.

 

edittext controls don't support click events I don't think. You'd have to use onActivate, but that doesn't work either.

 

If i change the window type to palette then the script just runs through and I see the window only for a subsecond...

 

You'd have to run the script in a target engine. Nowadays in InDesign there's no need for that when you run the script from the Scripts panel, onky when you run it straight from the ESTK. How that plays in FrameMaker I've no idea. Maybe FrameMaker (like Photoshop) doesn't support palettes.

 

P.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 27, 2020 0
K.Daube LATEST
Advocate ,
Oct 27, 2020

Copy link to clipboard

Copied

Thanks Peter for Your answer.

BTW in FM we can have palettes - the screen shot in my post shows it.

My thought was this: if there is no onXxxx trigger, then an eventlistener could add one..

I really wonder why the examples in my references work:

 

Event listeners allow you add interactivity and know what key/button is being pressed! Learn how to use them and pass variables through them! ---------------...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 27, 2020 0