Radio button issues

New Here ,
Apr 05, 2018

Copy link to clipboard

Copied

Below are this the question from my form. I have a radio button Yes/No set (named HMDA) and I want to force the applicant to answer the question without being able to skip over it.  I wrote the below code but it doesn't work properly.  If the applicant tries to skip the question an alert will appear letting them know they have to answer the question.  When they click ok to dismiss the alert - if they answer yes to the question my script works fine and they can move on to the next question on the form.  However, when they click ok to dismiss the alert - if they try to answer No to the question the alert appears again and they click ok to dismiss the alert then the No button will populate and then applicant can move on.

Script for my Question:

if(getField("HMDA").value=="Off")app.alert("If the applicant is an individual, is the collateral offered a residential dwelling? Please select Yes or No",1,0,"HMDA ERROR")

Also, how do I get rid of the Warning: "JavaScript Window" on my alert?

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

The error message is an Adobe's anti-spoofing mechanism.  In order to get rid of it the code has to be run from a privileged (trusted) location,i.e. not a document script.

You can read more about trust and privilege here:

Trust and Privilege in Acrobat Scripts

TOPICS
Acrobat SDK and JavaScript

Views

459

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

Radio button issues

New Here ,
Apr 05, 2018

Copy link to clipboard

Copied

Below are this the question from my form. I have a radio button Yes/No set (named HMDA) and I want to force the applicant to answer the question without being able to skip over it.  I wrote the below code but it doesn't work properly.  If the applicant tries to skip the question an alert will appear letting them know they have to answer the question.  When they click ok to dismiss the alert - if they answer yes to the question my script works fine and they can move on to the next question on the form.  However, when they click ok to dismiss the alert - if they try to answer No to the question the alert appears again and they click ok to dismiss the alert then the No button will populate and then applicant can move on.

Script for my Question:

if(getField("HMDA").value=="Off")app.alert("If the applicant is an individual, is the collateral offered a residential dwelling? Please select Yes or No",1,0,"HMDA ERROR")

Also, how do I get rid of the Warning: "JavaScript Window" on my alert?

Adobe Community Professional
Correct answer by Thom Parker | Adobe Community Professional

The error message is an Adobe's anti-spoofing mechanism.  In order to get rid of it the code has to be run from a privileged (trusted) location,i.e. not a document script.

You can read more about trust and privilege here:

Trust and Privilege in Acrobat Scripts

TOPICS
Acrobat SDK and JavaScript

Views

460

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
Apr 05, 2018 0
Adobe Community Professional ,
Apr 05, 2018

Copy link to clipboard

Copied

The error message is an Adobe's anti-spoofing mechanism.  In order to get rid of it the code has to be run from a privileged (trusted) location,i.e. not a document script.

You can read more about trust and privilege here:

Trust and Privilege in Acrobat Scripts

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...
Apr 05, 2018 1
New Here ,
Apr 05, 2018

Copy link to clipboard

Copied

Thank you.  That fixed one of the problems.

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...
Apr 05, 2018 0
Adobe Community Professional ,
Apr 05, 2018

Copy link to clipboard

Copied

Where did you add the code?

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...
Apr 05, 2018 0
Most Valuable Participant ,
Apr 06, 2018

Copy link to clipboard

Copied

Form fields can be clicked in any order. What do you mean by “skipped over it” in terms of PDF form filling?

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...
Apr 06, 2018 0
New Here ,
Apr 06, 2018

Copy link to clipboard

Copied

I added it to the HMDA radio button 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
Reply
Loading...
Apr 06, 2018 0
New Here ,
Apr 06, 2018

Copy link to clipboard

Copied

I don’t want the user to tab through/past the question without answering it.

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...
Apr 06, 2018 0
Most Valuable Participant ,
Apr 06, 2018

Copy link to clipboard

Copied

That is not a good idea. Imagine you clicked into the field by accident. You won't be able to close the file without filling in a value, which you might not want to do. There are much less intrusive ways of forcing a user to fill in a value. For example, set the field as required so it can't be submitted unless a value is entered into it.

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...
Apr 06, 2018 0
Adobe Community Professional ,
Apr 06, 2018

Copy link to clipboard

Copied

aprild49548367  wrote

I added it to the HMDA radio button field.

getField("HMDA").value    is the old value

event.value                       is the actual value

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...
Apr 06, 2018 0
New Here ,
Apr 06, 2018

Copy link to clipboard

Copied

Bernd Alheit how do I use your suggestions in my script? I don’t think I understand exactly what you are sayin. Thanks

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...
Apr 06, 2018 0
New Here ,
Apr 06, 2018

Copy link to clipboard

Copied

This form has to be printed, signed by the applicant and returned to the Banker. There is not a submit button but thank you for the suggestion.

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...
Apr 06, 2018 0
Adobe Community Professional ,
Apr 06, 2018

Copy link to clipboard

Copied

Replace

getField("HMDA").value

with

event.value   

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...
Apr 06, 2018 0
New Here ,
Apr 06, 2018

Copy link to clipboard

Copied

That made it worse (what did I do wrong).   When I changed the script to

if(event.value)app.alert("If the applicant is an individual, is the collateral offered a residential dwelling? Please select Yes or No",1,0,"HMDA ERROR")

If the applicant tries to skip the question an alert will appear letting them know they have to answer the question.  When they click ok to dismiss the alert - if they answer yes to the question the alert appears again and the have to click ok to dismiss the alert before they can move on to the next question on the form.  However, when they click ok to dismiss the alert - if they try to answer No to the question the alert appears again and they click ok to dismiss the alert then the No button will populate and when they try to tab to the next question the alert will appear again. Then they click ok to dismiss and then applicant can move on.

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...
Apr 06, 2018 0
Adobe Community Professional ,
Apr 06, 2018

Copy link to clipboard

Copied

Why do you remove =="Off" ?

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...
Apr 06, 2018 0
New Here ,
Apr 06, 2018

Copy link to clipboard

Copied

I don't know ... I put it back to the below and it reacted the exact same way as it first did.  Works perfectly when yes is clicked however, no still triggers the alert again before moving on.

if(event.value=="Off")app.alert("If the applicant is an individual, is the collateral offered a residential dwelling? Please select Yes or No",1,0,"HMDA ERROR")

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...
Apr 06, 2018 0
Adobe Community Professional ,
Apr 06, 2018

Copy link to clipboard

Copied

You'll need to do some debug to figure out what's going on. Add this line above your code

console.println(event.targetName + " : " + event.value);

This will tell you the name of the field that is running this code and  what "event.value" is returning when you tab past the radio button group. Getting the name of the field is important because I suspect the issue is not on the field you think it is. When the user tabs, the focus is changing to the next field.  When they click back on the original radio button the focus changes again to that field, causing he error message to popup for the second radio button group.

One way to mitigate this issue is to force the focus back onto original field with even.target.setFocus().

And just to be clear, this code is in the "OnBlur" event?

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...
Apr 06, 2018 0
New Here ,
Apr 06, 2018

Copy link to clipboard

Copied

I am unfamiliar with the debugger.  Does this appear to be what you are thinking I need to do?  Also, yes this code is in the "OnBlur" event.

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...
Apr 06, 2018 0
Adobe Community Professional ,
Apr 06, 2018

Copy link to clipboard

Copied

Yes That's exactly right, that's how it needs to be in the OnBlur code.

If the "undefined:undefined" result shown above is correct, it means this code is being run from some context other than an OnBlur event.

Also I'd suggest turning the Debugger off. All you need is the console to show messages.

You'll find a video tutorial on the Console here:

Free Video Content & Full Listing of Available Videos

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...
Apr 06, 2018 0
New Here ,
Apr 08, 2018

Copy link to clipboard

Copied

Is this better? I did the same console.prinln... on the field just after my HMDA radio buttons as well.  Now I'm not sure where to go from here to figure out what is wrong and how to fix it.

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...
Apr 08, 2018 0
Adobe Community Professional ,
Apr 08, 2018

Copy link to clipboard

Copied

No, it is not better. It looks like you are entering and running this code in the console window. That doesn't do anything. The whole point of debug is to figure out what is going on in the radio button code. So you have to add the "console.println" to the code in the OnBlur event. Then, when you tab between radio button groups the results will be printed in the console window.

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...
Apr 08, 2018 0
New Here ,
Apr 09, 2018

Copy link to clipboard

Copied

This is what I have now.  The first set I tried to tab past and the alert appeared.  I clicked ok to clear alert and then clicked Yes.  It moved me to the next field. (like I want it to)

The second set I tried to tab past and the alert appeared.  I clicked ok to clear alert and then clicked No.  The alert appeared again and once I clicked ok to clear the alert I could tab to the next field.

The script on my next field is onFocus and console.println(event.targetName+":"+event.vlaue);if(getField("HMDA").value=="Off")getField("HMDA").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
Reply
Loading...
Apr 09, 2018 0
Adobe Community Professional ,
Apr 09, 2018

Copy link to clipboard

Copied

Does the "next" field also have an OnBlur script?  And it this next field named "IWe have selected"?

So, on the second set, you'll notice that the HMDA value returned "Off" two times in a row. This is obviously the reason the message appeared two times in a row. So the "No" value is not being set before the field looses focus.

For the next test, change "event.value" to "event.target.value" in all locations where it appears.  This should provide better results.

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...
Apr 09, 2018 0
Adobe Community Professional ,
Apr 09, 2018

Copy link to clipboard

Copied

I just had another thought. Is the same OnBlur code on every one of the radio buttons, i.e. both the Yes and No buttons?

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...
Apr 09, 2018 0
Adobe Community Professional ,
Apr 09, 2018

Copy link to clipboard

Copied

I believe I have discovered the source of your issue. The "OnBlur" event is a widget level event. It happens for each individual radio button in the group, but the value is a Field level property, Its the same for all radio buttons in the group. If the Yes button is the first one in the group, then it receives focus first when the user tabs into the group. Then you hit the No button, the focus leaves the Yes Button, which fires the OnBlur Event on that button before the no button changes the value of the field. This situation is unique for radio buttons since there is always more than one widget per field.

What you want to do is capture the OnBlur only when the user is changing fields, not when they are changing radio buttons in the same group. There's no good way to do this, because there is no way to know where the focus is going next.

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...
Apr 09, 2018 0
New Here ,
Apr 09, 2018

Copy link to clipboard

Copied

So, if this way really isn't possible is there a different way to make the field required? I don't have to use radio buttons for the question.  I tried to default the radio button to Yes and then have an alert that made the applicant answer Yes or No in the alert however if the applicant answered No it didn't change the answer on the form.  Thanks for all your help.

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...
Apr 09, 2018 0
Adobe Community Professional ,
Apr 09, 2018

Copy link to clipboard

Copied

There is a way to do this, it's just complicated. For example, you can add On Focus script to every field on the form.

This script would save the name of the field that has the focus and use this saved value to decide whether or not the field focus is changing on a required field. For example, if the saved name and the current name are the same it would do nothing. But if they are different and the saved name was a required field, and didn't have a value, it displays the warning.

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...
Apr 09, 2018 0
New Here ,
Apr 10, 2018

Copy link to clipboard

Copied

Can you provide me an example of what the script would say?

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...
Apr 10, 2018 0
Adobe Community Professional ,
Apr 10, 2018

Copy link to clipboard

Copied

This is not a simple script. Would you be willing to pay for it?

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...
Apr 10, 2018 0
Most Valuable Participant ,
Apr 06, 2018

Copy link to clipboard

Copied

Yes, but "tab through a question" doesn't mean anything when the user can just click past it. You need to move from the concept to exactly what you want to happen, realising that PDF forms haven't been designed to enable this easily. You have to forbid actions in all successor fields after checking conditions. Consider too that fields have more than one action type, choose carefully.

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...
Apr 06, 2018 0