The fields interface allows to interact with the fields. Retrieve them, manipulate them and perform additional helper operations.

Hierarchy

  • Fields

Methods

  • Return all fields in the document optionally filtered by type.

    Parameters

    • Optional cb: null

      [Deprecated] Shouldn't be used anymore, please pass null instead.

    • Optional types: FieldType | FieldType[]

      Optional type filter. Specify a single type or an array of types to filter by. If not specified, all types will be returned.

    Returns BaseField[]

    All the fields - optionally filtered by type.

  • Return a field by id.

    Parameters

    • id: string

      The field id.

    Returns BaseField

    Returns the field with the specified id or null if not found.

  • Return a number of fields identified by their id.

    Parameters

    • ids: string[]

      Id list of the fields to return.

    Returns BaseField[]

    Returns the fields with the specified ids.

  • Return all fields matching by name.

    Parameters

    • name: string

      The name to search for.

    • Optional cb: null

      [Deprecated] Shouldn't be used anymore, please pass null instead.

    • Optional exact: boolean

      Optional flag to indicate if the search should be exact or not. Default is false.

    • Optional types: FieldType | FieldType[]

      Optional type filter. Specify a single type or an array of types to filter by. If not specified, all types will be returned.

    Returns BaseField[]

    Returns the fields matching the specified name.

  • Return all fields on the specified pages - optionally filtered by type.

    Parameters

    • pages: string | number | string[] | number[]

      Page can be specified by either index or id and either as a single value or an array of values.

    • Optional cb: null

      [Deprecated] Shouldn't be used anymore, please pass null instead.

    • Optional types: FieldType | FieldType[]

      Optional type filter. Specify a single type or an array of types to filter by. If not specified, all types will be returned.

    Returns BaseField[]

    Returns the fields on the specified pages.

  • Return all fields matching specified tags and are on the specified pages - optionally filtered by type.

    Parameters

    • tags: string | string[]

      Either a single tag or an array of tags to filter by.

    • pages: string | number | string[] | number[]

      Page can be specified by either index or id and either as a single value or an array of values.

    • cb: null

      [Deprecated] Shouldn't be used anymore, please pass null instead.

    • all: boolean

      Optional flag to indicate if all tags should be matched or any. Default is false.

    • Optional types: FieldType | FieldType[]

      Optional type filter. Specify a single type or an array of types to filter by. If not specified, all types will be returned.

    Returns BaseField[]

    Returns the fields matching the specified tags and pages.

  • Return all fields matching specified tags - optionally filtered by type.

    Parameters

    • tags: string | string[]

      Either a single tag or an array of tags to filter by.

    • cb: null

      [Deprecated] Shouldn't be used anymore, please pass null instead.

    • all: boolean

      Optional flag to indicate if all tags should be matched or any. Default is false.

    • Optional types: FieldType | FieldType[]

      Optional type filter. Specify a single type or an array of types to filter by. If not specified, all types will be returned.

    Returns BaseField[]

    Returns the fields matching the specified tags.

  • Copy the given field. This can be used to simply copy or move a field (in conjunction with DeleteField).

    Type Parameters

    Parameters

    • fieldOrId: string | BaseField

      The field to copy identified by id or object

    • targetPage: string | number

      The target page identified by index, id or name.

    • Optional cb: null

      [Deprecated] Shouldn't be used anymore, please pass null instead.

    • Optional tags: string[]

      Optional tags to assign to the field directly at creation time. Note that tags should not contain the '|' character. The tags of the source field will be merged with the specified tags.

    Returns T

    The copied field.

  • Create a new custom field for a specific sub type.

    Parameters

    • customType: string

      The custom field subtype as identified when registering the custom field.

    • page: string | number

      The page identified by index, id or name.

    • position: Point

      The position of the field on the page.

    • size: Size

      The size of the field on the page

    • Optional cb: null

      [Deprecated] Shouldn't be used anymore, please pass null instead.

    • Optional tags: string[]

      Optional tags to assign to the field directly at creation time. Note that tags should not contain the '|' character.

    Returns CustomField

    The newly created custom field.

  • Creates a new field of the specified type.

    Type Parameters

    Parameters

    • type: FieldType

      The field type to create. For custom fields, please use CreateCustomField instead.

    • page: string | number

      The page identified by index, id or name.

    • position: Point

      The position of the field on the page.

    • size: Size

      The size of the field on the page

    • Optional cb: null

      [Deprecated] Shouldn't be used anymore, please pass null instead.

    • Optional tags: string[]

      Optional tags to assign to the field directly at creation time. Note that tags should not contain the '|' character.

    Returns T

    The newly created field.

  • Deletes a field from the document.

    Parameters

    • fieldOrId: string | BaseField

      The field to delete identified by id or object

    Returns boolean

    Flag indicating if the field was deleted or not.

  • Get the current font size used in a text field as if fit to box would be enabled. This allows to set the fit to box options directly in the parameters. Note that you have to either specify the values or the defaults as below will be used. It will not use the field settings for it automatically.

    Parameters

    • fieldOrId: string | TextField

      The text field directly or the id of the text field.

    • callback: ((fontSize) => void)

      The callback will be triggered once the font size has been calculated and the value is passed as a parameter.

        • (fontSize): void
        • Parameters

          • fontSize: number

          Returns void

    • Optional withWrap: boolean

      Flag to control if text wrapping should be applied when calculating the font size. Default is false.

    • Optional minFontSize: number

      The minimum font size to use when calculating the font size. Default is -1 - meaning no minimum font size.

    • Optional maxFontSize: number

      The maximum font size to use when calculating the font size. Default is -1 - meaning no maximum font size.

    Returns void

  • Get the text as HTML where the rich text format is represented with the MegaEdit rich text format.

    Parameters

    • fieldOrId: string | TextField

      The text field directly or the id of the text field.

    • Optional cb: null

      [Deprecated] Shouldn't be used anymore, please pass null instead.

    • Optional includeFieldSettings: boolean

      If true, we will have styling tags for the field standard format too in the output. If false, we will have only the rich text formatting which differs from the field standard format. Default is false. Use it to display the format externally (e.g. in a HTML context).

    • Optional tagLimiters: string[]

      This is an array of size two where the first element is the opening tag, and the second element is the closing tag used as the tag limiter. Standard value is ['<' , '>'].

    • Optional entireTextFlow: boolean

      If this is true we will extract the text from an entire text flow if the field is part of it. If false, we will extract only the text from the field itself. Default is false.

    Returns string

    The text as HTML variant.

  • Returns the text flow chain the specified field is part of. It will return a list with at least one field (the source), but if there is a text flow configured, it will return the flow in order of the flow direction.

    Parameters

    • fieldOrId: number | TextField

      The text field directly or the id of the text field.

    Returns TextField[]

    An ordered list of text fields which makue up the entire text flow.

  • Measure the text within a field and retrieve information about it including the overflow text and the dimensions of the text.

    Parameters

    • fieldOrId: string | TextField

      The id of the field or the field object itself. Must be a text field.

    • cb: ((data) => void)

      The callback is triggered once the measurements are ready.

    Returns void

  • Renders a field to an image. This is useful to get a preview of the field.

    Parameters

    • fieldOrId: string | BaseField

      The field to render identified by id or object

    • width: number

      The width of the image in pixels. The height will be calculated automatically based on the aspect ratio of the field.

    • callback: ((image) => void)

      The callback is triggered once the image is ready and the image data is passed as a parameter in base 64 format.

        • (image): void
        • Parameters

          • image: string

          Returns void

    Returns void

  • Updates the appareance of a custom field. This is important if the underlaying data has been changed and the field needs to be updated to show the new data.

    Parameters

    • fieldOrId: string | CustomField

      The custom field directly or the id of the custom field.

    Returns boolean

    Flag indicating if the field was updated or not.

  • Save a range of fields in a single call. This is to improve performance, but is mandatory for text fields with text flow to ensure the text flow is correctly updated.

    Parameters

    • fields: BaseField[]

      The field objects to save.

    Returns void

  • Sets the image scale or zoom of an image field. Value is between 0 and 100 - and that can be used as a simplified call to use the zoom feature.

    Parameters

    • fieldOrId: string | ImageField

      The image field directly or the id of the image field.

    • value: number

      The zoom value to set. Value is between 0 and 100.

    Returns boolean

    Flag indicating if the image scale was set or not.

  • Set the text of the field in a limited HTML format. MegaEdit rich text format is only a very small subset and is very limited in what it can represent compared to HTML. This is the prefered method to set text with rich text formatting.

    Parameters

    • fieldOrId: string | TextField

      The text field directly or the id of the text field.

    • text: string

      The text to set including rich text formatting. Newlines are represented with '
      ' and Html entities may be decoded.

    • Optional cb: ((success?, self?, response?) => void)

      Optional callback to be triggered once the text has been set.

        • (success?, self?, response?): void
        • Parameters

          Returns void

    • Optional tagLimiters: string[]

      This is an array of size two where the first element is the opening tag, and the second element is the closing tag used as the tag limiter. Standard value is ['<' , '>'].

    Returns void

Generated using TypeDoc