-
1. Re: Is there a way that you can have two different text fields (email, phone) that one at least one of them must be completed before submitting the form? Can it be done using javascript in the validation tab? if so, how?
Sabian Zildjian Dec 2, 2014 9:26 AM (in response to Arr2-D2)The Field Properties have a "Required" check box that does this for you so all you have to do is check the box.
-
2. Re: Is there a way that you can have two different text fields (email, phone) that one at least one of them must be completed before submitting the form? Can it be done using javascript in the validation tab? if so, how?
try67 Dec 2, 2014 9:45 AM (in response to Sabian Zildjian)But if I understood correctly they want the validation to pass even if just one of the two fields is filled in. That won't work if they set both as required.
The solution is either to do everything with JavaScript or to use a script in the validate event of each fields that sets the other field as required (or not) based on the value of the current field.
-
3. Re: Is there a way that you can have two different text fields (email, phone) that one at least one of them must be completed before submitting the form? Can it be done using javascript in the validation tab? if so, how?
GKaiseril Dec 2, 2014 10:01 AM (in response to try67)Yes but you will need to write a custom validation script for each field and I would also use a custom JavaScript for the submit button to validate that one of the fields is completed before performing the submit action.
-
4. Re: Is there a way that you can have two different text fields (email, phone) that one at least one of them must be completed before submitting the form? Can it be done using javascript in the validation tab? if so, how?
Arr2-D2 Dec 2, 2014 11:54 AM (in response to GKaiseril)Great. Is there an example of a javascript(s) that I could use to do this? I am pretty knew to this. I haven't been able to come up with an example yet. Any help would be greatly appreciated.
-
5. Re: Is there a way that you can have two different text fields (email, phone) that one at least one of them must be completed before submitting the form? Can it be done using javascript in the validation tab? if so, how?
GKaiseril Dec 2, 2014 12:51 PM (in response to Arr2-D2)Here is one solution:
// mouse up action for submit button;
function GetField(cName) {
// get field object for cName field with error checking;
var oField = this.getField(cName);
if(oField == null) app.alert("Error accessing field named " + cName + "\nPleae verigy field name, spelling and capitalizeation.", 1, 0);
return oField;
} // end GetField function;
var oPhone = GetField("phone");
oPhone.required = oPhone.value == oPhone.defaultValue;
var oEmail = GetField("email");
oEmail.required = oEmail.value == oEmail.defaultValue;if(oPhone.required && oEmail.required) {
app.alert("Missing required fields.", 1, 0);
} else {
app.alert("Submitting form", 3, 0);
// additional code for submission;
} -
6. Re: Is there a way that you can have two different text fields (email, phone) that one at least one of them must be completed before submitting the form? Can it be done using javascript in the validation tab? if so, how?
Arr2-D2 Dec 2, 2014 7:02 PM (in response to GKaiseril)Thanks for the script. I'm trying to understand it. Is it something that I can just copy and paste to use as is, the text field are named "phone" & "email"? The button field is named "submit". I am using Acrobat Pro XI to create and edit the form in question. Am I correct in assuming that the script is actuated by clicking on and releasing the submit button. Is the first script used in both the "phone" & "email" fields in the validation tab" & the second script put somewhere in the submit button? I cannot find a place in the "submit" button properties to run a script. Like I said, I'm just a beginner at this so I'm trying to learn as well as get a solution to the issue. Thanks.
-
7. Re: Is there a way that you can have two different text fields (email, phone) that one at least one of them must be completed before submitting the form? Can it be done using javascript in the validation tab? if so, how?
GKaiseril Dec 3, 2014 7:29 AM (in response to Arr2-D2)
The code is a plain text file and you should use either the provided default JavaScript editor provided in Acrobat or change the default edit for use by Acrobat to a text editor.Field names are document dependent. So you may need to adjust the names "phone" and "email".
The script goes into the mouse up action for the submit button field.
-
8. Re: Is there a way that you can have two different text fields (email, phone) that one at least one of them must be completed before submitting the form? Can it be done using javascript in the validation tab? if so, how?
Arr2-D2 Dec 3, 2014 8:15 AM (in response to GKaiseril)We are getting close! I pasted the script, as written, in the mouse up action box above the mailto: command. The script is check both fields; however, it is requiring that both fields are completed prior to submission, just as if I had set them up as required fields under the general options tab. What I'm hoping to accomplish that it will allow me to submit the document if at least one or the other field has been filled.



