These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Capturing the use of the RETURN / ENTER key in a custom dialog

Nifty
Registered: Jan 16 2011
Posts: 17

Sorry, me again !
 
Thank you very much for all the help I've been given so far.
My custom search is working and well received with my colleagues.
 
One practical query that has been raised is whether I can set the text input box so that if the user types in his search word(s)and then presses the RETURN / ENTER key the dialog will execute the search without the need to select the SEARCH button placed lower down in the dialog form. This scenario occurs where the user doesn't want to change the other search settings and would mimic how the built in search dialogs work.
 
So, is it possible for me to detect the use of the RETURN / ENTER key either from within the text input box element or just across the whole dialog and on detection execute the search function.
 
All help/advice would be very much appreciated.
 
Kind Regards,
 
Nifty
Norfolk, England.
 
Using Acrobat 8.2.6 Pro with Windows XP Pro.

My Product Information:
Acrobat Pro 8.1.7, Windows
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
You have very little control over the fine behavior of the dialog. The JavaScript dialogs are very simple and set in their ways. However, most of the time pressing Return/Enter has the same the same effect as the user pressing OK. There are situations where Enter is interpreted differently, for example, when keyboard focus is on an Active dropdown list or a multi-line edit box. If the focus is on the cancel button the dialog is exited with Cancel.

Try it out.

Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script

Nifty
Registered: Jan 16 2011
Posts: 17
Thom,

I have been using a normal button labelled SEARCH to execute the search function and close the dialog box, using a coded "close".
I have discovered that if I use an OK button to execute the search then this will enable the RETURN/ENTER key to execute the search code too, thus achieving the original aim of this thread.

HOWEVER, this brings up a different problem.
At the moment when the SEARCH button is pressed it brings up an app.alert if the text box is empty and when alert is closed the dialog is still active and text can be typed into the box etc.
However, by using an OK button the app.alert appears as before but once this alert is closed the whole dialog is closed, i.e. it finishes running the COMMIT function.
Is there anyway to "exit" the commit function if the text field is empty so the user can return to the dialog and type some text in, or is it possible to program the commit function so that it returns the focus back to the text box?

Regards,

Nifty
thomp
Expert
Registered: Feb 15 2006
Posts: 4411
First, I don't know if you've discovered this or not, but you can change the text on the OK button to whatever you want using the "ok_name" property of the button element.

Next, to deal with the empty text box use the "validate" function for the dialog. Use a script like this:

var oRslt =dialog.store();

if(oRslt["txt1"] == "")
{
app.alert("please enter search text");
return false;
}
else
return true;


Thom Parker
The source for PDF Scripting Info
www.pdfscripting.com
Very Important - How to Debug Your Script