# Class: FieldManager

## Annotations.Forms. FieldManager

#### new FieldManager(annotationManager)

  Represents a tree of PDF Forms fields. @see Annotations.Forms.Field Allows adding, getting and visiting fields.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `annotationManager` | CoreControls.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` | Annotations.Forms.Field | obj |  |  | 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
    Annotations.Forms.Field

#### 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` | 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(event, field)

  Listener for field value changes.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `event` | * | Currently ignored
  `field` | Annotations.Forms.Field | The field whose value changed.

#### forEachField(callback)

  Calls the specified callback for each of the fields in the document.

  ##### Parameters:

  Name | Type | Description
  --- | --- | ---
  `callback` | function | The function that will be called for each field. The callback is passed the field object.

#### getCalculationOrder()

  Gets the calculation order. @see Annotations.Forms.FieldManager.setCalculationOrder

  ##### Returns:

  An array of field names.

  Type
    Array.<string>

#### 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
    Annotations.Forms.Field | Annotations.WidgetAnnotation

#### 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.

#### Search results