Copy link to clipboard
Copied
I have the following code on my Submit button set for Mouse Down.
Not sure where this code is messing up. I am trying to have the submit button check that all required fields are filled out and if they are to make 2 specific fields required.
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f.type != "button" && f.required === true){
if((f.type == "text" && f.value == "") || (f.type == "checkbox" && f.value == "Off")){
emptyFields++
}
}
} if (emptyFields = 0){
this.getField("Executive or Director Signature").required = true;
this.getField("Executive or Director Name").required = true;
}
Copy link to clipboard
Copied
Before getting into the issues in your code, the logic behind it doesn't make sense.
Why set the fields as required after the submit button is clicked? The entire point of this property is to validate it before submitting the form, not afterwards...
Technically, your issue is this line:
if (emptyFields = 0) {
It should be:
if (emptyFields == 0) {
Copy link to clipboard
Copied
Thanks for catching that. I would have looked at it for hours.
Two people are signing the form. The first person needs to be able to submit the form to the second person. I want the second person's signature line to be required after the first person presses submit.
Copy link to clipboard
Copied
Yes, I actually thought it might be something like that... In that case, it does make sense, of course.
I would also change this line:
if((f.type == "text" && f.value == "") || (f.type == "checkbox" && f.value == "Off")){
To:
if(f.valueAsString==f.defaultValue){
It will help you cover all field types, not just text fields and check-boxes.
Copy link to clipboard
Copied
Thanks for that.
I will change that code as well.
Now I'm encountering a different issue.
If I set it for Mouse Down it will turn the fields required and block the person from submitting.
If I set it for Mouse Up or On Blur it does not turn them required.
Copy link to clipboard
Copied
You should use MouseUp, but you should also add the Submit command to the script, as you can't cancel the submit command if it's not done using the script.
Add this to the end of your code:
else this.mailDoc({cTo: "target@server.com"});