Class: FieldManager

Core.Annotations.Forms. FieldManager


new FieldManager(annotationManager)

Represents a tree of PDF Forms fields. @see Core.Annotations.Forms.Field Allows adding, getting and visiting fields.
Parameters:
Name Type Description
annotationManager Core.AnnotationManager

Methods


addField(field [, update])

Adds the given field object to the field tree, either replacing or merging with any existing field. Note: if the field is merged, it is the equivalent of performing Annotations.Forms.Field.set on the existing field, followed by setting all the field's widgets' fields to the original field.
Parameters:
Name Type Argument Default Description
field Core.Annotations.Forms.Field | object The field or field-like object to add.
update boolean <optional>
false
Returns:
The field that was inserted into the field tree (may not be the field originally provided).
Type
Core.Annotations.Forms.Field

areRequiredFieldsFilled()

iterate over every field and check if it's required and if it has a value
Returns:
Returns True if there is no required field or all fields are filled out, false otherwise
Type
boolean

calculate(field [, index])

Equivalent to the given field's value changing, if it was at position index in the calculation order.
Parameters:
Name Type Argument Default Description
field Core.Annotations.Forms.Field <nullable>
The field to set as source for the calculation event. May be null.
index number <optional>
0 The index at which to start running the calculation order.

fieldChanged(field)

Listener for field value changes.
Parameters:
Name Type Description
field Core.Annotations.Forms.Field The field whose value changed.

forEachField(callback)

Calls the specified callback for each of the root fields in the document. If there is a tree of form fields, then this will only iterate over root fields. Please use Core.Annotations.Forms.Field.children and a tree traversal algorithm to traverse the fields. If you know the name of your field, you can use Core.Annotations.Forms.FieldManager.getField.
Parameters:
Name Type Description
callback function The function that will be called for each field. The callback is passed the field object.
Example
const stack = [];
        fieldManager.forEachField(function(field) {
         stack.push(field); // Push root fields
       });
        while (stack.length > 0) {
         const current = stack.pop();
         if (current.isTerminal()) {
           // Work with terminal/leaf fields
         }
         else {
           // Traverse children
           stack = stack.concat(current.children);
         }
       }

getField(name)

Gets a field whose full name matches the one that is given. If No field matches, and the last part of the field name is a number, returns that index of the field's widget array.
Parameters:
Name Type Description
name string The full name of the field to search for.
Returns:
The field or widget, or null if no field matches.
Type
Core.Annotations.Forms.Field | Core.Annotations.WidgetAnnotation

getFields()

Returns an array of all field objects in the document
Returns:
Type
Array.<Core.Annotations.Forms.Field>

print()

Invokes the available print handler to print the document Note: This method requires Embedded JavaScript to not have been disabled with Core.disableEmbeddedJavaScript

setAlertHandler(handler)

Updates the function to be used for handling alert messages for field validation.
Parameters:
Name Type Description
handler function The function that will handle alert messages. It will be called with a string representing the alert message.

setCalculationOrder(order)

Set the calculation order - use this if you need changes in one field to trigger calculation events on other fields. If the name of field that is changed is before the name of another field, that other field is recalculated. If the name of the field that has changed is not in the array, all the fields named by the arrya are recalculated in order.
Parameters:
Name Type Description
order Array.<string> An array of field names.

setPrintHandler()

Sets the function to be used to handle the print API called by embedded PDF JavaScript

updateFieldName(field, name)

Renames the field that is passed to the name passed in.
Parameters:
Name Type Description
field Core.Annotations.Forms.Field | object The field that should be renamed.
name string The name of the field to be renamed. Cannot be blank.
Returns:
The renamed field.
Type
Core.Annotations.Forms.Field | Core.Annotations.WidgetAnnotation