Copy link to clipboard
Copied
Hi Guys
I've designed a PDF form and have used a button to check all required fields are completed. The problem is the button won't accept any fields with a zero(0) amount. Is there any around this?
Thanks
Copy link to clipboard
Copied
Replace
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
with
if ((f.type=="text" && f.valueAsString=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
nothing more
Copy link to clipboard
Copied
What code does you use?
Copy link to clipboard
Copied
Hi
JavaScript, but I was hoping there was another way around this?
Regard
Ciaran
Copy link to clipboard
Copied
Acrobat will check the required fields when you submit the form.
Copy link to clipboard
Copied
Hi
I know. When it check the fields it won't accept zero or 0 as an entry, it will read it as a blank cell. I need it to read the fields as complete?
Copy link to clipboard
Copied
What format does you use in the field.
Copy link to clipboard
Copied
Either none or ideally number with no decimal places or separators?
Copy link to clipboard
Copied
Submit form accepts 0's.
Copy link to clipboard
Copied
This one doesn't.
Copy link to clipboard
Copied
It works in my form.
Copy link to clipboard
Copied
I must be missing something simple. What would you suggest I try? Could I email the document to you?
Copy link to clipboard
Copied
Can you share the file with us (via Dropbox, Google Drive, Adobe Document Cloud, etc.)?
Copy link to clipboard
Copied
Hi Guy
Please check New Start Form.pdf - Google Drive
Copy link to clipboard
Copied
Sorry guys please try Dropbox - New Start Form.pdf
Copy link to clipboard
Copied
This this editable document Adobe Document Cloud
Copy link to clipboard
Copied
Use
f.valueAsString==""
not
f.value==""
When you test it in the console you will see this:
0=="";
true
"0"=="";
false
Copy link to clipboard
Copied
Hi
I tried inserting the below script but it doesn't work? Or maybe I'm putting it into the wrong field. Which field should I use?
f.valueAsString==""
0=="";
true
"0"=="";
false
Copy link to clipboard
Copied
In the button "Confirm" use:
if ((f.type=="text" && f.valueAsString=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
Copy link to clipboard
Copied
Should I replace the existing script that alerts the user of required fields that are incomplete or will I add this script it to the existing script?
Copy link to clipboard
Copied
You must replace one line of the existing script.
Copy link to clipboard
Copied
Which line should I remove the original script?
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f= this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required ) {
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
}
}
if (emptyFields.length>0) {
app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
}
if ((f.type=="text" && f.valueAsString=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
Copy link to clipboard
Copied
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
Copy link to clipboard
Copied
I appreciate you patience but I inserted the below script buts its not working?
var emptyFields = [];
for (var i=0; i<this.numFields; i++) {
var f= this.getField(this.getNthFieldName(i));
if (f.type!="button" && f.required ) {
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
}
}
if (emptyFields.length>0) {
app.alert("Error! You must fill in the following fields:\n" + emptyFields.join("\n"));
}
f.valueAsString==""
0=="";
true
"0"=="";
false
Copy link to clipboard
Copied
Replace
if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
with
if ((f.type=="text" && f.valueAsString=="") || (f.type=="checkbox" && f.value=="Off")) emptyFields.push(f.name);
nothing more
Copy link to clipboard
Copied
Thank you so much for your help its perfect now.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now