Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Switch specific fields from required to not required based on any text entered in a specific field.

Explorer ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

Tried researching several threads and can't seem to find anything specific to what i'm hoping is possible, but working on a new form and looking for help with creating a javascript as well as where exactly it would be placed.

 

The scenario is I have 8 separate fields, with 7 of 8 fields that are by default on the form required.

 

The 8 fields are comprised of:

-3 text fields (Text1, Text2, and Text3)

-2 dropdown fields (Dropdown1 and Dropdown2)

-2 radio button fields (Group1 and Group2)

-1 check box field (Check Box1)

 

("Text1" Field is essentially the parent field and is not required but all other fields as listed above are required.)

 

The action I want to occur in my form, is that if a user enters any type of text into the "Text1" field, it switches all of those 7 other fields to no longer be required.

 

On the flipside, if say a user did enter/type any text into "Text1" field, but then changes their mind (or was a mistake) and clears out whatever they typed into that "Text1" field, then I want those 7 fields to switch back to being required again or require a value or response.

 

I feel like I confused myself re-reading back what I need, so I hope that all makes sense to you out there. lol.

 

Appreciate the time and any help someone can offer!  🙂

TOPICS
Create PDFs, General troubleshooting, JavaScript, PDF forms

Views

48

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
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Aug 26, 2021 Aug 26, 2021
You may achieve this with a validation script. You may use a similar (or better) script like the example below. event.rc = false; var f = event.value; if (f !=="") { this.resetForm(["Text2", "Text3", "Dropdown1", "Dropdown2", "Group1", "Group2", "Check Box1"]); this.getField("Text2").required = false; this.getField("Text3").required = false; this.getField("Dropdown1").required = false; this.getField("Dropdown2").required = false; this.getField("Group1").required = false; this.getFiel...

Likes

Translate

Translate
Adobe Community Professional ,
Aug 26, 2021 Aug 26, 2021

Copy link to clipboard

Copied

You may achieve this with a validation script.

 

You may use a similar (or better) script like the example below.

 

 

event.rc = false;

var f = event.value;

if (f !=="")  {

this.resetForm(["Text2", "Text3", "Dropdown1", "Dropdown2", "Group1", "Group2", "Check Box1"]); 

this.getField("Text2").required = false;
this.getField("Text3").required = false;
this.getField("Dropdown1").required = false;
this.getField("Dropdown2").required = false;
this.getField("Group1").required = false;
this.getField("Group2").required = false;
this.getField("Check Box1").required = false;

this.getField("Text2").readonly = true;
this.getField("Text3").readonly = true;
this.getField("Dropdown1").readonly = true;
this.getField("Dropdown2").readonly = true;
this.getField("Group1").readonly = true;
this.getField("Group2").readonly = true;
this.getField("Check Box1").readonly = true;

event.rc = true;

} else {

if(f =="") {

app.alert("Please fill in the required fields.");

event.rc = 
this.getField("Text2").required = true;
this.getField("Text3").required = true;
this.getField("Dropdown1").required = true;
this.getField("Dropdown2").required = true;
this.getField("Group1").required = true;
this.getField("Group2").required = true;
this.getField("Check Box1").required = true;


this.getField("Text2").readonly = false;
this.getField("Text3").readonly = false;
this.getField("Dropdown1").readonly = false;
this.getField("Dropdown2").readonly = false;
this.getField("Group1").readonly = false;
this.getField("Group2").readonly = false;
this.getField("Check Box1").readonly = false;


 }
}


 

 

  1. Copy the script above, then  open the "Prepare Form" tool, right-click on the parent field ("Text1"), and select from the context menu "Properties".
  2. Click on the "Validate" tab, then tick the radio button labeled "Run custom validation script:", and then click on the "Edit" button.
  3. The JavaScript editor window will open up, where you can paste this script
  4. Click on the "Close" button to exit the JavaScript editor after you've paste the script
  5. Click "Close" again from the "Prepare Form" toolbar to exit this editing mode and save your work.

 

You should be able to see the results immediately when you type in data in Text1 or delete the data in Text1.

 

NOTE:

I added a read only option to the script just in case you don't want users typing data on those 7 fields when Text1 is not empty,  and to be able to identify more clearly when these fields are required (bordered in red frame color) and an alert that notify the user(s) to fill them in.

 

Let us know if this meet your requirement(s). 

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
community guidelines
Explorer ,
Aug 27, 2021 Aug 27, 2021

Copy link to clipboard

Copied

Yes perfect!  This is great especially the app alert added.  Your awesome!  Thanks for figuiring this out was a huge 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
community guidelines
Adobe Community Professional ,
Aug 27, 2021 Aug 27, 2021

Copy link to clipboard

Copied

LATEST

You're welcome.

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
community guidelines