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

Latest code & example

Explorer ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Here is the latest code and now it is not working when I click on NO, it owuld reset the fields.  NOw that is broken.

 

 

Everyone,

  I followed this page for  conditional editing:

https://answers.acrobatusers.com/How-I-conditionally-set-required-fields-form-based-user-answers-rad...

 

  Yet this dod not work for me.  I created hidden text field and created the code. It is not working,  then I added to the Mouse Up event on the Radio Button and still is not working.

This what I am trying to do.  Also, what I will need to also figure out is iof the check NO, then I want to initialize the fields to the default value.  I.E. Year = "Select a year (Default value on the List Dropdown)", the other 2 fields are spaces.

If the button is Yes,

    Unprotect the 3 fields and make them required
Else

 IF the button is No, then

   protect the 3 fields and make them not required.

 

Here is my javacript code:

var vYesNo = this.getField("Trade_Yes_No_Grp").value;
var vYearCar = this.getField("Year_Drop_Down");
var vCarMake = this.getField("CMake");
var VCarModel = this.getField("CModel");

 

vYearCar.required = false;
vCarMake.required = false;
vCarModel.required = false;

vYearCar.protected = true;
vCarMake.protected = true;
vCarModel.protected = true;

 

if (vYesNo == "Yes")
{
vYearCar.required = true
vCarMake.required = true
vCarModel.required = true
vYearCar.protected = false
vCarMake.protected = false
vCarModel.protected = false;
}
else if (vYesNo == "No")
{
vYearCar.required = false
vCarMake.required = false
vCarModel.required = false
vYearCar.protected = true
vCarMake.protected = true
vCarModel.protected = true;
}

 

Can someone plz let me know what si wrong with this code or where I should put this java script and the even which it should happen under.  Thanx in advance.

 

Jerry

 

TOPICS
Acrobat SDK and JavaScript

Views

500

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 , Aug 31, 2020 Aug 31, 2020

You shouldn't be running that code in both radio button fields.

 

Since you have them set as mutually exclusive all you have to do is split the code.

 

Use this part of your script in the YES Radio Button:

 

//SCRIPT FOR THE YES RADIO BUTTON

this.getField("Year_Drop_Down").required = true;
this.getField("CMake").required = true;
 this.getField("CModel").required = true;
this.getField("Year_Drop_Down").readonly = false;
this.getField("CMake").readonly = false;
this.getField("CModel").readonly = 
...

Votes

Translate

Translate
Community Expert ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

- Place the code as the Mouse Up event of both radio-buttons.

- You can remove the entire first part of it (between the variable declarations and the if-statement).

- There's no property called "protected" in an Acrobat form. Use "readonly", instead.

- To reset the fields if "No" is selected add this command to that section of the code:

this.resetForm(["Year_Drop_Down", "CMake", "CModel"]);

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
Explorer ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

Try67,

 

  Everything works excluding the protection of the fields when the user clicks "No".  Everything else is great.  It resets the form fine.  Yet, I can go to the fields and enter data.  Trying to make these fields protected so the user cannot get to them.  Here is the code now and any thoughts on what I am doing wrong.  Both radio buttons have the same code in them.

 

if (vYesNo == "Yes")
{
vYearCar.required = true
vCarMake.required = true
vCarModel.required = true
vYearCar.readonly = false
vCarMake.readonly = false
vCarModel.readonly = false;
}
else if (vYesNo == "No")
{
this.resetForm(["Year_Drop_Down", "CMake", "CModel"])
vYearCar.required = false
vCarMake.required = false
vCarModel.required = false
vYearCar.readonly = true
vCarMake.readonly = true
vCarModel.readonly = true;
}

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 ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

The code seems fine. Are there any error messages in the JS Console when you use it? Can you share the file with us?

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
Explorer ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

I cannot see how to attach the file.  Here is my latest code:

if (vYesNo == "Yes")
{
vYearCar.required = true
vCarMake.required = true
vCarModel.required = true
this.getfield("vYearCar").readonly = false
this.getfield("vCarMake").readonly = false
this.getfield("vCarModel").readonly = false;
}
else if (vYesNo == "No")
{
this.resetForm(["Year_Drop_Down", "CMake", "CModel"])
vYearCar.required = false
vCarMake.required = false
vCarModel.required = false
this.getfield("vYearCar").readonly = true
this.getfield("CarMake").readonly = true
this.getfield("vCarModel").readonly = true;
}

 

  If I could attach it, then I would the whole thing.

Jerry

 

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 ,
Aug 30, 2020 Aug 30, 2020

Copy link to clipboard

Copied

This version is worse, since you used an incorrect function name. It's getField, not getfield... Go back to the previous version.

 

In order to share the file you can attach it to the original message using the tiny paperclip icon at the bottom when you edit it, or upload it to a file-sharing website (like Dropbox, Google Drive, Adobe Cloud, etc.), generate a share link and then post it here.

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 ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

Where does you set the variables vYesNo, vYearCar, and so 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 ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

Or with the PDF opened in Acrobat just click on the share file icon(it has a paperclip and cloud icons) to the far right of the main toolbar. Clicking on this link will upload your copy automatically to the document cloud and generate a share link. It will turn to green with a checkmark when the link has been copied (to the clipboard).

 

All you have to do is paste that link here in the messaging chatbox where you're replying.

 

 

So what happen?  something went "Boop, Boop, Boop" instead of "Beep, Boop, Beep" ?!?  (just messing..)

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 ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

You shouldn't be running that code in both radio button fields.

 

Since you have them set as mutually exclusive all you have to do is split the code.

 

Use this part of your script in the YES Radio Button:

 

//SCRIPT FOR THE YES RADIO BUTTON

this.getField("Year_Drop_Down").required = true;
this.getField("CMake").required = true;
 this.getField("CModel").required = true;
this.getField("Year_Drop_Down").readonly = false;
this.getField("CMake").readonly = false;
this.getField("CModel").readonly = false;

 

 

And use this part in the NO Radio Button:

 

//place this in no radio button
this.getField("Year_Drop_Down").required = false;
this.getField("CMake").required = false;
this.getField("CModel").required = false;
this.getField("Year_Drop_Down").readonly = true;
this.getField("CMake").readonly = true;
this.getField("CModel").readonly = true;

this.resetForm(["Year_Drop_Down", "CMake", "CModel"])

 

That's it.

 

You had the same chunk of script in both radio buttons. If you do it as illustrated in my example you don't need to complicate yourself so much with conditional statements.

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 ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

But if you still want to run the mouse-up action code entirely  from the " YES"  Radio Button only, then this works too:

 

if (event.value !=="Off") {

if (event.target.value = "Yes") {

this.getField("Year_Drop_Down").required = true;
this.getField("CMake").required = true;
 this.getField("CModel").required = true;
this.getField("Year_Drop_Down").readonly = false;
this.getField("CMake").readonly = false;
this.getField("CModel").readonly = false;

} else {

this.getField("Year_Drop_Down").required = false;
this.getField("CMake").required = false;
this.getField("CModel").required = false;
this.getField("Year_Drop_Down").readonly = true;
this.getField("CMake").readonly = true;
this.getField("CModel").readonly = true;

this.resetForm(["Year_Drop_Down", "CMake", "CModel"])

 }

}

 

 

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
Explorer ,
Aug 31, 2020 Aug 31, 2020

Copy link to clipboard

Copied

LATEST

Great answer and exactly correct!  I appreciate it very much and wish everyone and their families to be safe during these times.


Jerry

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