Highlighted

Latest code & example

Community Beginner ,
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

 

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

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.

TOPICS
Acrobat SDK and JavaScript, Create PDFs, Edit and convert PDFs, General troubleshooting, How to, PDF forms, Standards and accessibility

Views

83

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

Latest code & example

Community Beginner ,
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

 

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

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.

TOPICS
Acrobat SDK and JavaScript, Create PDFs, Edit and convert PDFs, General troubleshooting, How to, PDF forms, Standards and accessibility

Views

84

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
Aug 30, 2020 0
Most Valuable Participant ,
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"]);

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...
Aug 30, 2020 0
Community Beginner ,
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;
}

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...
Aug 30, 2020 0
Most Valuable Participant ,
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?

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...
Aug 30, 2020 0
Community Beginner ,
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

 

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...
Aug 30, 2020 0
Most Valuable Participant ,
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.

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...
Aug 30, 2020 0
Adobe Community Professional ,
Aug 31, 2020

Copy link to clipboard

Copied

Where does you set the variables vYesNo, vYearCar, and so 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...
Aug 31, 2020 0
Adobe Community Professional ,
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..)

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...
Aug 31, 2020 0
Adobe Community Professional ,
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.

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...
Aug 31, 2020 0
Adobe Community Professional ,
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"])

 }

}

 

 

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...
Aug 31, 2020 0
ballj_35 LATEST
Community Beginner ,
Aug 31, 2020

Copy link to clipboard

Copied

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


Jerry

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