Getting a button to unhide when someone hits "enter" inside a field

Explorer ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

So I have sort of a solution to this already, but I am adapting something that was a spreadsheet to a PDF file that does calculations and we want a callout box to become visible after someone puts a value in a specific field. I have it set up to unhide the object (which is set up as a button within InDesign) upon blur of the field, but my client is asking if it can happen when someone hits "enter" in the field. I personally think people will tab from one field to the next, but given that this used to be a spreadsheet, I can see how she might have a point about the expected behavior of people hitting "enter" after typing numbers.

 

Is this at all possible? The form starts with the field blank and any value should trigger this callout, so if there's a way to do this with event value, that seems like it would be acceptable, but I have no idea how to go about setting that up outside of the actions.

TOPICS
JavaScript, PDF forms

Views

94

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
community guidelines

correct answers 1 Correct Answer

Explorer , Mar 08, 2021 Mar 08, 2021
OOOOH, based on this and some more reading, I think I have it now? In the validation script, I set a variable for the event value and a variable that relates to the button. var RatioEntered = (event.value != 0); var ShowRatioCallout = this.getField("Ratio"); ShowRatioCallout.display = RatioEntered?display.visible:display.hidden; I got the method from most of the way down the page here and it appears to work with positive and negative values (and disappears if I put zero back in, but if people wa...

Likes

Translate

Translate
Most Valuable Participant ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

It is possible, but it's a bit tricky. In order to do it you must define the text field as Multiline, and then use something like this as its custom Keystroke script (under Properties - Format - Custom):

 

if (event.change=="\n") {this.getField("Button1").display = display.visible; event.rc = false;}

 

Replace "Button1" with the actual name of your field.

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
community guidelines
Most Valuable Participant ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Addendum: If you also want that pressing Enter will cause it to jump to the next field, use the following:

 

if (event.change=="\n") {
	this.getField("Button1").display = display.visible; 
	event.rc = false;
	this.getField("Name of next field in tab order").setFocus();
}

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
community guidelines
Explorer ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Mmmmm, okay, so my first thought is that I don't love what it does visually to the field to do that, because it's really pushing the number down (top left field has been set to multi-line and top right field hasn't been changed yet). Is it possible to mess with the padding inside? I also increased the text size to get it to display prominently and now when I hit enter, my computer is dinging to indicate there's an error because there's no room below for another line.

kateb89895260_0-1615229027249.png

 

I also haven't added the code yet because there's already a custom format script here and I don't know entirely how to combine the two if statements, if you are able to guide me there:

if (event.value !=="" && !isNaN(event.value)){

event.value = util.printf("%.0f%",event.value);

}else{

event.value = "";

}

I think ideally we don't want enter to push focus to the next field (which has its own callout). I think what the client likes about hitting enter after the user inputs the percentage is that it kind of has them sit with the data that is generated underneath for a bit and encourages them to go back and tinker with the number to change the results. Though what I had (tripping the callout box on blur) also had them either tabbing out to a different box or clicking outside the field, which doesn't encourage that behavior either.

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
community guidelines
Adobe Community Professional ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Not sure if it's right way but this worked for me:

Use as validation script :

if(!event.target.setFocus())
this.getField("Text1").display = display.visible;

 This should unhide field when enter is pressed after value is entered.

Replace field name if needed.

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
community guidelines
Explorer ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

Hmmm, I used that as a custom validation script and it is not unhiding the button with either the main enter key or the number pad entery key. But thank you for trying!

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
community guidelines
Adobe Community Professional ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

For me it works with both enter buttons.

I see you found solution fo yourself, if you are interested here is an example file I made, you can test and see if it works for you 🙂

https://drive.google.com/uc?export=download&id=1aByTNADUiv9AHtoqM3SyMXqUgUAyRIu_ 

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
community guidelines
Explorer ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

LATEST

No idea why it worked here but not on mine, other than the thing I was hiding/showing was a button and not a form field? I appreciate you showing me the result, though!

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
community guidelines
Explorer ,
Mar 08, 2021 Mar 08, 2021

Copy link to clipboard

Copied

OOOOH, based on this and some more reading, I think I have it now? In the validation script, I set a variable for the event value and a variable that relates to the button.

 

var RatioEntered = (event.value != 0);
var ShowRatioCallout = this.getField("Ratio");
ShowRatioCallout.display = RatioEntered?display.visible:display.hidden;

 

I got the method from most of the way down the page here and it appears to work with positive and negative values (and disappears if I put zero back in, but if people want these fields to be 0, then they won't really need the callout, so it's fine).

 

https://www.pdfscripting.com/public/Hiding-and-Showing-Form-Fields.cfm 

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
community guidelines