Thebboii04
Thebboii04

Reputation: 55

interactive PDF Form-Validation Javascript

I'm trying to validate my interactive PDF. So if i click on a button (for validating) there's following code behind it:

var isBlank = false;
var blank = "Please fill following fields:";
var isNotValid = false;
var notValid = "Please check input data in following fields:";
var message = "";

var t = ['Division', 'Oragnisationseinheit', 'Name', 'KZZ', 'Privataddresse'];
var i;

for(var i=0; i<t.length;i++){
  //validation text fields needs to be filled in
  if (this.getField(t[i]).value == "") {
   blank = blank + "\n" + this.getField(t[i]).name;
   isBlank = true;
  }

  //validation text field must contain only lower case letters
  if (/^[a-z]*$/.test(this.getField(t[i]).value) == false) {
   notValid = notValid + "\n" + this.getField(t[i]).name;
   isNotValid = true;
  }

  //generate message
  if (isBlank == true) {
   message = blank + "\n" + "\n";
  }
  if (isNotValid == true) {
   message = message + notValid;
  }
}
//check all conditions
if ((isBlank == true) || (isNotValid == true)) {
 //show message
 app.alert({ cMsg: message, cTitle: "Input data error" });
}

The problem is now, if I press the button there's no reaction. --> the var message wont being displayed. Where is the issue?

Thanks for all ideas.

Upvotes: 1

Views: 241

Answers (1)

joelgeraci
joelgeraci

Reputation: 4927

You might try instead to add a custom validation script that would first check to be sure the field isn't blank and if not, simply change the input to lower case so the user doesn't need to modify the field themselves.

Add the following code to the custom field validate script. This should work for any text field.

if (event.value.length == 0) {
    app.alert({ cMsg: event.target.name + " cannot be blank.", cTitle: "Input data error" });
}
else {
    event.value = event.value.toLowerCase();
} 

Upvotes: 2

Related Questions