Help needed to amend a javascript that checks required fields

Participant ,
Dec 19, 2019 Dec 19, 2019

Copy link to clipboard

Copied

I have a button on my form that checks thats all required fields have been completed before continuing.

One of the required fields is a monetary field. If it's blank, the error message appears as it should, but if 0,00 is typed in, the error message is still appearing saying the field needs to be completed.

This is the code on the button, but I'm not sure what to actually change so it literally only appears if the fields are blank (it ignores 0,00)

 

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.userName);

}

}

if (emptyFields.length>0) {

app.alert("ERREUR. Au moins une de ces informations suivantes est manquante.\nVous devez compléter l’ensemble de ces informations afin de pouvoir soumettre votre dossier\n\n" + emptyFields.join("\n"));
}
else
this.getField("HIDE.LockDoc").display = display.visible;
{ // All is ok, submit the data
console.println("Votre bon de commande est complet, vous pouvez le soumettre");
}

 

 

TOPICS
Acrobat SDK and JavaScript, PDF forms

Views

254

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Most Valuable Participant , Dec 19, 2019 Dec 19, 2019
That's an old version of this code I wrote. Change this line in it: if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off")) To: if (f.valueAsString==f.defaultValue)

Likes

Translate

Translate
Most Valuable Participant ,
Dec 19, 2019 Dec 19, 2019

Copy link to clipboard

Copied

That's an old version of this code I wrote. Change this line in it:

if ((f.type=="text" && f.value=="") || (f.type=="checkbox" && f.value=="Off"))

To:

if (f.valueAsString==f.defaultValue)

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 19, 2019 Dec 19, 2019

Copy link to clipboard

Copied

LATEST

Thank you as always @try67  🙂

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines