Skip to main content
Known Participant
April 3, 2019
Answered

How do you make a required field accept zero(0) value?

  • April 3, 2019
  • 2 replies
  • 5216 views

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

This topic has been closed for replies.
Correct answer Bernd Alheit

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


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

2 replies

NCL STORE
Participating Frequently
April 4, 2019

What code does you use?

NCL STORE - Siêu thị tiện ích thông minh
Bernd Alheit
Community Expert
Community Expert
April 3, 2019

What code does you use?

CiaranMHRAuthor
Known Participant
April 3, 2019

Hi

JavaScript, but I was hoping there was another way around this?

Regard

Ciaran

Bernd Alheit
Community Expert
Community Expert
April 3, 2019

Acrobat will check the required fields when you submit the form.