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! 🙂
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;
}
}
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).
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;
}
}
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).
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! 🙂
Copy link to clipboard
Copied
You're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now