Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help needed to amend a javascript that checks required fields

Contributor ,
Dec 19, 2019 Dec 19, 2019

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
849
Translate
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

Community Expert , 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)

Translate
Community Expert ,
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)

Translate
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
Contributor ,
Dec 19, 2019 Dec 19, 2019
LATEST

Thank you as always @try67  🙂

Translate
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