Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    Class DataModelValidationFailure

    A class responsible for recording information about a validation failure.

    Index

    Properties

    dropped: boolean

    Whether the value was dropped from some parent collection.

    If this field contains a list of elements that are validated as part of its validation, their results are recorded here.

    fallbackValue: any

    The value it was replaced by, if any.

    fieldPath: string

    The path of the field responsible for the failure.

    fields: Record<string, DataModelValidationFailure> = {}

    If this field contains other fields that are validated as part of its validation, their results are recorded here.

    invalidValue: any

    The value that failed validation for this field.

    joint: string

    If this field contains a list of elements that are validated as part of its validation, their results are recorded here.

    message: string

    The error message.

    options: Error

    Options forwarded to the Error constructor.

    unresolved: boolean

    Record whether a validation failure is unresolved. This reports as true if validation for this field or any hierarchically contained field is unresolved. A failure is unresolved if the value was invalid and there was no valid fallback value available.

    Accessors

    • get empty(): boolean

      Whether this failure contains other sub-failures.

      Returns boolean

    Methods

    • Generate a nested tree view of the error as an HTML string.

      Returns string

    • Retrieve a flattened object of all the properties that failed validation as part of this error.

      Returns Record<string, DataModelValidationFailure>

      const changes = {
      "foo.bar": "validValue",
      "foo.baz": "invalidValue"
      };
      try {
      doc.validate(expandObject(changes));
      } catch ( err ) {
      const failures = err.getAllFailures();
      if ( failures ) {
      for ( const prop in failures ) delete changes[prop];
      doc.validate(expandObject(changes));
      }
      }
    • Retrieve the leaf node failure that caused this, or a specific sub-failure via a path.

      Parameters

      • Optionalkey: string

        The property key to the failure.

      Returns DataModelValidationFailure | null

      const changes = {
      "foo.bar": "validValue",
      "foo.baz": "invalidValue"
      };
      try {
      doc.validate(expandObject(changes));
      } catch ( err ) {
      const failure = err.getFailure("foo.baz");
      console.log(failure.invalidValue); // "invalidValue"
      }
    • Log the validation error as a table.

      Returns void

    • Return the base properties of this failure, omitting any nested failures.

      Returns { dropped: boolean; fallbackValue: any; invalidValue: any; message: string }

    • Represent the DataModelValidationFailure as a string.

      Returns string