Is that Field Empty?

As a form designer, you can be almost certain that there will be a time when you’ll need to check a field to see whether its value is empty (whether the form filler has specified a value).

For longest time, I had been doing it like this in *JavaScript*:

bc. if (theField.rawValue ====== null || theField.rawValue.length ====== 0)
// field is empty
// field has been filled

p. That served me quite well until yesterday when I found myself needing to do the same, but this time in *FormCalc*. Theoretically, the following should’ve worked:

bc. if (theField ====== null | theField ====== “”) then
// field is empty
// field has been filled

But for some reason, the FormCalc interpreter was giving me a hard time with the _null_ keyword (maybe it’s because I don’t use it very often and it was upset at me, I don’t know — if you’re a developer, you’ll understand that sometimes, code can have feelings and a mind of its own 😉 ) so was forced to try and find some other way to check if a field’s value is null in FormCalc and I found one:

bc. theField.isNull

The *isNull* property (of the XFA Scripting Model’s _node_ object) “indicates whether the current *data value* is the null value”, as stated on page 422 of the “Adobe XML Form Object Model Reference”: (located in the XML section).

This means that the following *JavaScript* expression checks whether a field’s value is empty:

bc. (theField.isNull || theField.rawValue.length ====== 0)

And in *FormCalc*:

bc. (theField.isNull | theField ====== “”)

One Response to Is that Field Empty?

  1. Karen says:

    I have also used HasValue(theField) for FormCalc