Copy link to clipboard
Copied
Hello all.
I am learning a bit of Javascript and have come up with the script below, however i cannot get the final line to work correctly. Is 'null' incorrect? I have a pdf form with several data fields and am trying to force certain answers when the user selects an option. For example below, when the user selects 'Regal', the next two data fields will be populated with N/A. However i still want the user to be able to select the 'Tap hole' option and henceforth need this datafield to be blank. If i just leave this line out it seems to break my form. Any help is much appreciated. Thanks
if (event.value=="Regal") {
this.getField("Top Colour").setItems(["N/A"]);
this.getField("Basin").setItems(["N/A"]);
this.getField("Tap Holes").setItems("null");
Copy link to clipboard
Copied
Yes, it's incorrect.
Either use this:
this.getField("Tap Holes").setItems([""]);
Or this:
this.getField("Tap Holes").clearItems();
Copy link to clipboard
Copied
Yes, it's incorrect.
Either use this:
this.getField("Tap Holes").setItems([""]);
Or this:
this.getField("Tap Holes").clearItems();
Copy link to clipboard
Copied
Thanks @try67 thats worked perfectly.
I am also running this javascript i found online for the submit button however the last part of the script isn't work. It does everything except for emailing the order. Is there something that stands out as been incorrect?
app.runtimeHighlight = false;
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required && (f.display != display.hidden)) {
if (( f.value=="") || (f.value==" ")){
f.strokeColor = color.red; //use this to change to the colour to require
emptyFields.push(f.userName);
}
}
}
if (emptyFields.length>0) {
app.alert({
cMsg: "Please fill out the follwing fields before submission:\n\n" + emptyFields.join("\n"), cTitle: "Required Fields"})
}
else {
for (var i = 0 ; i < this.numFields ; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f.type != "Submit")
{
f.readonly = true;
}
}
this.mailDoc({
cTo: "email@myemail.com",
cSubject: "This is your email subject",
cMsg: "This is your email body message"
});
}
Copy link to clipboard
Copied
This is based off of code I wrote, but someone added parts to it which are incorrect.
Do you want to set all the fields as read-only before submitting the file?
Also, the first line of the code disables the fields highlighting for all documents. It's not a good idea to include it, generally speaking.
Copy link to clipboard
Copied
Why not simply use the built-in Submit a Form command?
Copy link to clipboard
Copied
Sorry, i was using it because it removed the red border around every required field when the form was opened (as well as the blue box) and meant that the red border only reappeared around empty data fields when the user tried to submit the form. Is there anyway i can remove the highlighting from this document only rather that the whole application?
Copy link to clipboard
Copied
No, but you can inform the user about it and suggest to them to turn it off.
You didn't answer about whether you want to set the fields as read-only, as that code also (attempts) to do that...
Copy link to clipboard
Copied
Yes i was changing all the fields to read only when the client tries to submit it. I guess it was a way to lock the details in the form before the client emails it.
Copy link to clipboard
Copied
OK, try this version of that code, then:
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f = this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required && (f.display != display.hidden)) {
if (( f.value=="") || (f.value==" ")){
f.strokeColor = color.red; //use this to change to the colour to require
emptyFields.push(f.userName);
}
}
}
if (emptyFields.length>0) {
app.alert({ cMsg: "Please fill out the follwing fields before submission:\n\n" + emptyFields.join("\n"), cTitle: "Required Fields"});
} else {
for (var i = 0 ; i < this.numFields ; i++) {
var f = this.getField(this.getNthFieldName(i));
f.readonly = true;
}
this.mailDoc({
cTo: "email@myemail.com",
cSubject: "This is your email subject",
cMsg: "This is your email body message"
});
}
Copy link to clipboard
Copied
You are a legend. That works pefectly, Thank you.
Copy link to clipboard
Copied
I didn't notice it before, but I would change line #5 in the code above from this:
if (( f.value=="") || (f.value==" ")){
To this:
if (f.valueAsString==f.defaultValue) {
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more