• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Radio button issues

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

TOPICS
Acrobat SDK and JavaScript

Views

1.2K

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

Community Expert , Apr 05, 2018 Apr 05, 2018

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

Votes

Translate

Translate
Community Expert ,
Apr 05, 2018 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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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

Copy link to clipboard

Copied

Thank you.  That fixed one of the problems.

Votes

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
Community Expert ,
Apr 05, 2018 Apr 05, 2018

Copy link to clipboard

Copied

Where did you add the code?

Votes

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
LEGEND ,
Apr 06, 2018 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?

Votes

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

Copy link to clipboard

Copied

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

Votes

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

Votes

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

Votes

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

Copy link to clipboard

Copied

I added it to the HMDA radio button field.

Votes

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
Community Expert ,
Apr 06, 2018 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

Votes

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

Votes

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
Community Expert ,
Apr 06, 2018 Apr 06, 2018

Copy link to clipboard

Copied

Replace

getField("HMDA").value

with

event.value   

Votes

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

Votes

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
Community Expert ,
Apr 06, 2018 Apr 06, 2018

Copy link to clipboard

Copied

Why do you remove =="Off" ?

Votes

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
New Here ,
Apr 06, 2018 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")

Votes

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
Community Expert ,
Apr 06, 2018 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?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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

Votes

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
Community Expert ,
Apr 06, 2018 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

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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

Votes

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
Community Expert ,
Apr 08, 2018 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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
New Here ,
Apr 09, 2018 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()

Votes

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
Community Expert ,
Apr 09, 2018 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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
Community Expert ,
Apr 09, 2018 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?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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
Community Expert ,
Apr 09, 2018 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.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

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

Votes

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