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

Making a field required

Community Beginner ,
Mar 17, 2025 Mar 17, 2025

Copy link to clipboard

Copied

Hi all,

I am working on a form with yes and no check boxes. This is one of the questions:

 

Did you verify the account activiny is in line with the investment profile?

No (If no, please explain.): ____________________

Yes

 

Is there a way if "No" is selected, the field to please explain is required for them to move on? If they choose 'No', then they MUST explain?

 

Conversely, is there a if 'Yes' is selected, the field to explain is locked down and they cannot enter any information? This one is not as important, but our reps need hand holding any chance they can get. So, we were thinking to lock down the explain field when 'Yes' is selected.

 

TIA!

 

TOPICS
How to , PDF forms

Views

216
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
1 ACCEPTED SOLUTION
Community Expert ,
Mar 18, 2025 Mar 18, 2025

Copy link to clipboard

Copied

Use this code:

 

if (this.getField("IPYN").valueAsString=="1") {
	event.target.required = true;
	event.target.readonly = false;
} else {
	event.target.required = false;
	event.target.readonly = true;
	event.value = "";
}

 

I also applied it already for you in the attached file.

View solution in original post

Votes

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 Employee ,
Mar 17, 2025 Mar 17, 2025

Copy link to clipboard

Copied

Hi @,

 

Hope you are doing well. Thanks for writing in!

 

You can try the below steps and let us know if it works:

  1. Open your PDF form in Acrobat.
  2. Go to Prepare Form mode.
  3. Name the fields as follows for reference:
    • "Yes_Checkbox"
    • "No_Checkbox"
    • "Explain_Field"
  4. Right-click on the No_Checkbox, select Properties > Actions tab.
  5. Under Select Trigger, choose Mouse Up.
  6. Under Select Action, choose Run a JavaScript, then click Add.
  7. Enter the following
    1. if (this.getField("No_Checkbox").value === "Yes") {
          this.getField("Explain_Field").required = true;
      } else {
          this.getField("Explain_Field").required = false;
      }

Next, lock "Explain" Field When 'Yes' is Selected

  1. Right-click the Yes_Checkbox, select Properties > Actions tab.
  2. Under Select Trigger, choose Mouse Up.
  3. Under Select Action, choose Run a JavaScript, then click Add.
  4. Enter this
    1. if (this.getField("Yes_Checkbox").value === "Yes") {
          this.getField("Explain_Field").readonly = true;
          this.getField("Explain_Field").value = ""; // Clears text if already entered
      } else {
          this.getField("Explain_Field").readonly = false;
      }

Note: This is a sample code that might or might not work for you. I am no expert with Scripting, and this is something I tried at my end.

 

Hope this helps.


Regards,
Souvik.

Votes

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 Beginner ,
Mar 17, 2025 Mar 17, 2025

Copy link to clipboard

Copied

Thank you, Souvik! I will try now... quick question - when I rename the checkboxes, do I use the quotation marks?

 

"Yes_Checkbox" or Yes_Checkbox

 

Kind regards,

April

Votes

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 ,
Mar 17, 2025 Mar 17, 2025

Copy link to clipboard

Copied

No, don't use them in the field names, only in your code.

Votes

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 Beginner ,
Mar 17, 2025 Mar 17, 2025

Copy link to clipboard

Copied

Thank you!

Votes

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 Beginner ,
Mar 17, 2025 Mar 17, 2025

Copy link to clipboard

Copied

Any chance you are available for a Zoom? lol I can't get it to work... 😞

Votes

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 ,
Mar 17, 2025 Mar 17, 2025

Copy link to clipboard

Copied

If you'll provide more details we could help you out, but just saying "it doesn't work" is not very useful to us...

Votes

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 Beginner ,
Mar 17, 2025 Mar 17, 2025

Copy link to clipboard

Copied

That's fair, my apologies!

 

I followed the above directions, but nothing happened. The field doesn't become required when no is selected, and the field doesn't become locked down when yes is selected.

 

Thank you again!

Votes

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 ,
Mar 17, 2025 Mar 17, 2025

Copy link to clipboard

Copied

Check the JS Console (Ctrl+J) for error messages. If you still can't figure it out, share the file with us, please.

Votes

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 Beginner ,
Mar 17, 2025 Mar 17, 2025

Copy link to clipboard

Copied

Hello - Thank you for the feedback! I didn't get any error messages. This is the form in question. 

 

Much, much appreciated!  🙂 April

Votes

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 ,
Mar 18, 2025 Mar 18, 2025

Copy link to clipboard

Copied

I don't see any code anywhere in this file...

Votes

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 ,
Mar 18, 2025 Mar 18, 2025

Copy link to clipboard

Copied

PS. I had a closer look at the instructions above and they are not correct. You need to place both codes under both check-boxes for it to work properly. And of course you need to adjust the field names and values in them.

And actually, a better option is to do it through the Calculation event of the text field itself... I will adjust the code and send a new version soon.

Votes

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 ,
Mar 18, 2025 Mar 18, 2025

Copy link to clipboard

Copied

Use this code:

 

if (this.getField("IPYN").valueAsString=="1") {
	event.target.required = true;
	event.target.readonly = false;
} else {
	event.target.required = false;
	event.target.readonly = true;
	event.value = "";
}

 

I also applied it already for you in the attached file.

Votes

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 Beginner ,
Mar 18, 2025 Mar 18, 2025

Copy link to clipboard

Copied

LATEST

THANK YOU, Try67!!! This worked and I genuinely appreciate the help and time on this! 🙂

Votes

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