Skip to main content
Known Participant
April 9, 2019
Answered

conditional required field

  • April 9, 2019
  • 2 replies
  • 3371 views

I want to make a dropdown list (drop1) as a required field with alert message: (please enter the delay code)

if the difference between two fields (time1) (time2) is more than 00:05 (0.083333333333333) as a decimal value

And if the difference is lower than (00:05)

It will not be a required field

I want to make this script by JavaScript

Any help please !?

This topic has been closed for replies.
Correct answer try67

it works but when the dropdown list "DEPCODE1#1" is not required , the alert massege and return action still working

how i can fix this ??

thank you in advance


Change this line:

if(this.getField("DEPCODE1#1").value == "")

To:

if(this.getField("DEPCODE1#1").required && this.getField("DEPCODE1#1").value == "")

2 replies

Participant
August 30, 2020

I'm new to javascript. I've browsed the forum and tried every solution that I've come across here and yet still stuck with the mySaveAs function giving me the same error no matter what my button script is in my AcroForm.  I'm not able to figure out how to resolve this error. Appreciate all the help and assistance. Thanks in advance.

ERROR:

UnsupportedValueError: Value is unsupported. ===> Parameter cPath.
Doc.saveAs:7:Field Save:Mouse Up

 

Below are my Scripts.

Folder level script:

var mySaveAs = app.trustedFunction(

function(doc,path) {

app.beginPriv();

doc.saveAs(path);

app.endPriv();

}
);

myTrustedSpecialTaskFunc = app.trustedFunction(

function(doc,path) {

app.beginPriv();

try {

mySaveAs(doc,path);

} catch (e) {

app.alert("Error During Save - " + e);

}

app.endPriv();

}
);


Mouse-up Button script:
//
// Before saving the data, make sure that all required
// fields are valid
//
function myDateSTring(){
return util.printd("mm/dd/yyyy h:MMtt", new Date());
}
if(FormValidFields())
{

var directory = "/C/Users/aUsers/Folder/Subfolder/";

var SignedOffBy = this.getField('SignedOffBy');
if (this.getField("SignedOffBy").value == "SignedOffBy.valueAsString"){
SignedOffBy = SignedOffBy.valueAsString;
}
var myFileName = SignedOffBy + " - " + myDateSTring() + ".pdf";
var mySaveAs = directory + myFileName;
if (typeof(mySaveAs) == "function") {
mySaveAs(this, directory, SignedOffBy +"-"+ myDateSTring()+".pdf");
app.alert("This Form " + SignedOffBy +"-"+ myDateSTring()+ " has saved successfully to the following location: /C/Users/aUsers/folder/subfolder/" , 3);
} else {
app.alert("Missing Save Function. Please contact forms administrator ");
}

}

 

Thom Parker
Community Expert
Community Expert
April 9, 2019

For this solution I'm assuming that by (00:05), you mean 5 minutes. The general method is to create a hidden field and add a calculation script that finds the time difference and then sets the required property of the dropdown based on the result.

// Get time values in milliseconds

var time1 = util.scand("..Time Format...", this.getField("time1").value).getTime();

var time2 = util.scand("..Time Format...", this.getField("time2").value).getTime();

// Get difference in minutes

var nDiffMin = (time1-time2)/60000;

this.getField("drop1").required = (nDiffMin > 5);

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often
Known Participant
April 9, 2019

Mr. thom i tried many times to reach you

can we i contact you by email

i have many topics i want to discuss with you for my project

thank you

abdalla

<personal email removed by moderator>

Thom Parker
Community Expert
Community Expert
April 9, 2019

Just sent you a message.

Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often