Is there a way to determine which field has focus from javascript? Or if a field has focus?
I want to be able to programmatically add some text and a date to the current field, but can't figure out how to know which field is active.
[javascript] determine if field has focus SOLVED
Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan
-
- User
- Posts: 239
- Joined: Thu Jun 19, 2014 7:30 pm
-
- Site Admin
- Posts: 17960
- Joined: Mon Jan 12, 2009 8:07 am
- Location: London
Re: [javascript] determine if field has focus
Hello Mathew,
Would listening for the Field/Focus event work for you? Or do you need to check which is the active field at a time when a script is run manually and is not constantly listening for that event?
Kind regards,
Stefan
Would listening for the Field/Focus event work for you? Or do you need to check which is the active field at a time when a script is run manually and is not constantly listening for that event?
Kind regards,
Stefan
You do not have the required permissions to view the files attached to this post.
-
- User
- Posts: 239
- Joined: Thu Jun 19, 2014 7:30 pm
Re: [javascript] determine if field has focus
Stefan,
Yes, I'm looking to add text to the currently selected field.
But you bring up an interesting approach, although it's very intrusive because it makes changes to the current document whether I plan to add text to it or not: I could add the OnFocus and OnBlur actions to set a custom property on all text fields. Then I just check for that property in a script that's run from the menu.
Unfortunately I think it clobbers the current action (if any) on the field, and I don't think there's a way to access that current action (?), so can't restore it or add to it. Would need to somehow monitor for newly opened document, add the events. I think it's problematic as a general tool though.
Yes, I'm looking to add text to the currently selected field.
But you bring up an interesting approach, although it's very intrusive because it makes changes to the current document whether I plan to add text to it or not: I could add the OnFocus and OnBlur actions to set a custom property on all text fields. Then I just check for that property in a script that's run from the menu.
Code: Select all
{
let f = this.getField("Text1");
f.setAction("OnFocus", "this.focus=true;");
f.setAction("OnBlur", "this.focus=false;");
}
-
- Site Admin
- Posts: 306
- Joined: Sun Nov 21, 2004 3:19 pm
Re: [javascript] determine if field has focus
Hi Mathew,
I do not currently see an non-intrusive way to achieve that. We will consider adding hasFocus property to Field object, as an PDF-XChange extension to the Acrobat JS API.
I do not currently see an non-intrusive way to achieve that. We will consider adding hasFocus property to Field object, as an PDF-XChange extension to the Acrobat JS API.
-
- User
- Posts: 239
- Joined: Thu Jun 19, 2014 7:30 pm
Re: [javascript] determine if field has focus
Thank you Roman and Stefan. For now, I'll figure out some sort of workaround, but I'll look forward to the day of .hasFocus as an additional property...
- Mathew.
- Mathew.
-
- Site Admin
- Posts: 8624
- Joined: Wed Jan 03, 2018 6:52 pm
[javascript] determine if field has focus
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Tracker Software Products (Canada) LTD
+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
-
- Site Admin
- Posts: 306
- Joined: Sun Nov 21, 2004 3:19 pm
-
- User
- Posts: 239
- Joined: Thu Jun 19, 2014 7:30 pm
-
- Site Admin
- Posts: 306
- Joined: Sun Nov 21, 2004 3:19 pm
Re: [javascript] determine if field has focus
Actually, we have implemented it as a method, not property, to be more consistent with the existing Acrobat API ( Field.setFocus() ).