Skip to main content
Known Participant
December 19, 2019
Answered

Help needed to amend a javascript that checks required fields

  • December 19, 2019
  • 1 reply
  • 831 views

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");
}

 

 

This topic has been closed for replies.
Correct answer try67

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)

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 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)

jlehaneAuthor
Known Participant
December 19, 2019

Thank you as always @try67  🙂