Skip to main content
JR Boulay
Community Expert
Community Expert
April 29, 2024
Answered

Zero = empty… Is it a new bug ?

  • April 29, 2024
  • 2 replies
  • 484 views

Hi experts

 

I think I'm dealing with a new bug in Acrobat: JavaScript no longer knows the difference between nothing and zero.

 

Look at the attached file, there are three buttons, the top one tests if the value is equal to the default value, the middle one tests if the value is nothing and the bottom one tests if the value is zero.
In all cases the answer is the same, whether the fields contain zero or nothing.

 

Have I done something wrong or is this really a bug?


The scripts are in the buttons, this is the first one :

nCompteur = 0;
for (var i=0; i<this.numFields; i++) {
	var oFld = this.getField(this.getNthFieldName(i));
	if (oFld.type != "button" && oFld.required == true && oFld.value == oFld.defaultValue) {
		oFld.strokeColor = color.red;
		nCompteur = nCompteur + 1;
	}
}

console.println("nCompteur = " +nCompteur);

if (nCompteur != 0) {app.alert({cMsg: "At least one field has not been filled in.\nFields that are not filled in are marked in red.", cTitle: "TITLE", nIcon: 1});}
else {app.alert({cMsg: "All fields are filled in", cTitle: "TITLE", nIcon: 1});}

 

Thank you

 

 

This topic has been closed for replies.
Correct answer Nesa Nurani

You can use strict equality to check for empty: oFld.value === ""

2 replies

JR Boulay
Community Expert
JR BoulayCommunity ExpertAuthor
Community Expert
April 29, 2024

Thank you Nesa, you're the best!
But why didn't I think of this before? It will remain one of the great mysteries of my life. 😉

Acrobate du PDF, InDesigner et Photoshopographe
Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
April 29, 2024

You can use strict equality to check for empty: oFld.value === ""