Reputation: 13
In this code:
this.getField("myField").value == null;
this.getField("myField").value === null;
typeof this.getField("myField").value == null;
typeof this.getField("myField").value === null;
this.getField("myField").rawValue === null;
this.getField("myField").formattedValue === "";
this.getField("myField").isNull;
this.getField("myField").isNull == True;
all of the above exchanging 'null' for 'Null', encapsulated 'Null', and 'undefined'.
In each circumstance all I get is:
TypeError: this.getField(...) is null
23:Field:Blur
How do I see if a field is null? I do not want to have default values because not every field on the form needs to be used and should be able to be blank.
Upvotes: 1
Views: 2841
Reputation: 4917
Generally... meaning you used an application rather than a library to create the form... PDF field values will never be null. An empty field has a zero-length string as the default value. To test if the field is empty use...
if (this.getField("myField").value.length == 0) {
// do something
}
else {
// it has a value
}
or
if (this.getField("myField").value == "") {
// do something
}
else {
// it has a value
}
Upvotes: 0
Reputation: 1074258
If you're getting that error, it's because this.getField("myField")
itself is returning null
. So any attempt to use a property on what it returns will fail.
It sounds like you need a null
guard:
var field = this.getField("myField");
if (field !== null) }
// use `field.value` here...
}
Upvotes: 1