Search code examples
javascriptadobeacrobat

Adobe Acrobat 2017 Javascript is null?


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.


Solution

  • 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
    }