Options
All
  • Public
  • Public/Protected
  • All
Menu

Class that allows us to manage application validation in an encapsulated way. We can create as many instances as we want, and each instance will store the validation history and global validation state, so we can use this class to validate complex forms or multiple elements globally. We can also use tags to sandbox different validation elements or groups togheter.

Hierarchy

  • ValidationManager

Index

Properties

Private _failedMessages

_failedMessages: { message: string; tag: string }[] = []

Stores a list of all the validation error or warning messages that have happened since the validation manager was created or since the last reset was performed.

Each message is stored with its associated tag.

Private _validationStatus

_validationStatus: { status: number; tag: string }[] = [{tag: '',status: ValidationManager.OK}]

Stores the current validation state for each one of the defined tags.

tag contains the name of the tag for which we are saving the status status can have 3 different values: OK / WARNING / ERROR

Static Readonly ERROR

ERROR: 2 = 2

Constant that defines the error validation status

Static Readonly OK

OK: 0 = 0

Constant that defines the correct validation status

Static Readonly WARNING

WARNING: 1 = 1

Constant that defines the warning validation status

Methods

Private _updateValidationStatus

  • _updateValidationStatus(result: boolean, errorMessage: string, tags?: string | string[], isWarning: boolean): boolean
  • Update the class validation Status depending on the provided error message.

    Parameters

    • result: boolean

      the result of the validation

    • errorMessage: string

      The error message that's been generated from a previously executed validation method

    • Default value tags: string | string[] = ""

      The tag or list of tags that have been defiend for the validation value

    • isWarning: boolean

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    True if received errorMessage was '' (validation passed) or false if some error message was received (validation failed)

getFirstMessage

  • getFirstMessage(tags?: string | string[]): string
  • Find the first error or warning message that happened since the validation manager was instantiated or since the last reset

    Parameters

    • Default value tags: string | string[] = ""

    Returns string

    The first error or warning message or empty string if no message exists

getLastMessage

  • getLastMessage(tags?: string | string[]): string
  • Find the latest error or warning message that happened since the validation manager was instantiated or since the last reset

    Parameters

    • Default value tags: string | string[] = ""

    Returns string

    The last error or warning message or empty string if no message exists

getStatus

  • getStatus(tags?: string | string[]): number
  • Check the current validation state. Possible return values are ValidationManager.OK, ValidationManager.WARNING or ValidationManager.ERROR

    Parameters

    • Default value tags: string | string[] = ""

      If we want to check the validation state for a specific tag or a list of tags, we can set it here. If we want to get the global validation state for all the tags we will leave this value empty ''.

    Returns number

    ValidationManager.OK, ValidationManager.WARNING or ValidationManager.ERROR

isArray

  • isArray(value: any, errorMessage?: string, tags?: string | string[], isWarning?: boolean): boolean
  • Validation will fail if specified value is not an array

    Parameters

    • value: any

      The array to validate

    • Default value errorMessage: string = "value is not an array"

      The error message that will be generated if validation fails

    • Default value tags: string | string[] = ""

      We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state

    • Default value isWarning: boolean = false

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    False in case the validation fails or true if validation succeeds.

isBoolean

  • isBoolean(value: any, errorMessage?: string, tags?: string | string[], isWarning?: boolean): boolean
  • Validation will fail if specified value is not a boolean

    Parameters

    • value: any

      The boolean to validate

    • Default value errorMessage: string = "value is not a boolean"

      The error message that will be generated if validation fails

    • Default value tags: string | string[] = ""

      We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state

    • Default value isWarning: boolean = false

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    False in case the validation fails or true if validation succeeds.

isDate

  • isDate(): boolean
  • Returns boolean

isEqualTo

  • isEqualTo(value: any, value2: any, errorMessage?: string, tags?: string | string[], isWarning?: boolean): boolean
  • Validation will fail if specified elements are not identical.

    Parameters

    • value: any

      First of the two objects to compare. Almost any type can be provided: ints, strings, arrays...

    • value2: any

      Second of the two objects to compare. Almost any type can be provided: ints, strings, arrays...

    • Default value errorMessage: string = "values are not equal"

      The error message that will be generated if validation fails

    • Default value tags: string | string[] = ""

      We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state

    • Default value isWarning: boolean = false

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    False in case the validation fails or true if validation succeeds.

isFilledIn

  • isFilledIn(value: any, emptyChars?: any[], errorMessage?: string, tags?: string | string[], isWarning?: boolean): boolean
  • Validation will fail if specified text is empty.
    See Stringutils.isEmpty to understand what is considered as an empty text

    see

    Stringutils.isEmpty

    Parameters

    • value: any

      A text that must not be empty.

    • Default value emptyChars: any[] = []

      Optional array containing a list of string values that will be considered as empty for the given string. This can be useful in some cases when we want to consider a string like 'NULL' as an empty string.

    • Default value errorMessage: string = "value is required"

      The error message that will be generated if validation fails

    • Default value tags: string | string[] = ""

      We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state

    • Default value isWarning: boolean = false

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    False in case the validation fails or true if validation succeeds.

isHtmlFormValid

  • isHtmlFormValid(string: string): boolean
  • Parameters

    • string: string

    Returns boolean

isMail

  • isMail(): boolean
  • Returns boolean

isMaximumLength

  • isMaximumLength(string: string): boolean
  • Parameters

    • string: string

    Returns boolean

isMinimumLength

  • isMinimumLength(string: string): boolean
  • Parameters

    • string: string

    Returns boolean

isMinimumWords

  • isMinimumWords(string: string): boolean
  • Parameters

    • string: string

    Returns boolean

isNIF

  • isNIF(string: string): boolean
  • Parameters

    • string: string

    Returns boolean

isNumeric

  • isNumeric(value: any, errorMessage?: string, tags?: string | string[], isWarning?: boolean): boolean
  • Validation will fail if specified value is not numeric

    Parameters

    • value: any

      The number to validate

    • Default value errorMessage: string = "value is not a number"

      The error message that will be generated if validation fails

    • Default value tags: string | string[] = ""

      We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state

    • Default value isWarning: boolean = false

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    False in case the validation fails or true if validation succeeds.

isNumericBetween

  • isNumericBetween(value: any, min: number, max: number, errorMessage?: string, tags?: string | string[], isWarning?: boolean): boolean
  • Validation will fail if specified value is not numeric and between the two provided values.

    Parameters

    • value: any

      The number to validate

    • min: number

      The minimum accepted value (included)

    • max: number

      The maximum accepted value (included)

    • Default value errorMessage: string = "value is not between min and max"

      The error message that will be generated if validation fails

    • Default value tags: string | string[] = ""

      We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state

    • Default value isWarning: boolean = false

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    False in case the validation fails or true if validation succeeds.

isObject

  • isObject(value: any, errorMessage?: string, tags?: string | string[], isWarning?: boolean): boolean
  • Validation will fail if specified value is not an object

    Parameters

    • value: any

      The object to validate

    • Default value errorMessage: string = "value is not an object"

      The error message that will be generated if validation fails

    • Default value tags: string | string[] = ""

      We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state

    • Default value isWarning: boolean = false

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    False in case the validation fails or true if validation succeeds.

isPhone

  • isPhone(string: string): boolean
  • Parameters

    • string: string

    Returns boolean

isPostalCode

  • isPostalCode(string: string): boolean
  • Parameters

    • string: string

    Returns boolean

isString

  • isString(value: any, errorMessage?: string, tags?: string | string[], isWarning?: boolean): boolean
  • Validation will fail if specified value is not a string

    Parameters

    • value: any
    • Default value errorMessage: string = "value is not a string"

      The error message that will be generated if validation fails

    • Default value tags: string | string[] = ""

      We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state

    • Default value isWarning: boolean = false

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    False in case the validation fails or true if validation succeeds.

isTrue

  • isTrue(value: any, errorMessage?: string, tags?: string | string[], isWarning?: boolean): boolean
  • Validation will fail if specified value is not a true boolean value

    Parameters

    • value: any

      A boolean expression to validate

    • Default value errorMessage: string = "value is not true"

      The error message that will be generated if validation fails

    • Default value tags: string | string[] = ""

      We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state

    • Default value isWarning: boolean = false

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    False in case the validation fails or true if validation succeeds.

isUrl

  • isUrl(value: any, errorMessage?: string, tags?: string | string[], isWarning?: boolean): boolean
  • Validation will fail if specified value is not an url

    Parameters

    • value: any

      The element to validate

    • Default value errorMessage: string = "value is not an URL"

      The error message that will be generated if validation fails

    • Default value tags: string | string[] = ""

      We can define a tag name or list of tags to group the validation results. We can use this tags later to filter validation state

    • Default value isWarning: boolean = false

      Tells if the validation fail will be processed as a validation error or a validation warning

    Returns boolean

    False in case the validation fails or true if validation succeeds.

notOk

  • notOk(tags?: string | string[]): boolean
  • Provides a way to perform a fast validation check. Will return true if validation manager is in a warning or error state, or false if validation state is ok.

    Parameters

    • Default value tags: string | string[] = ""

      If we want to check the validation state for a specific tag or a list of tags, we can set it here. If we want to get the global validation state for all the tags we will leave this value empty ''.

    Returns boolean

    True if status is warning or error, False if status is ok

ok

  • ok(tags?: string | string[]): boolean
  • Provides a way to perform a fast validation check. Will return true if validation state is ok, or false if validation manager is in a warning or error state.

    Parameters

    • Default value tags: string | string[] = ""

      If we want to check the validation state for a specific tag or a list of tags, we can set it here. If we want to get the global validation state for all the tags we will leave this value empty ''.

    Returns boolean

    True if status is ok, false if status is warning or error

reset

  • reset(): void
  • Reinitialize the validation status.

    This is normally called at the beginning of every global validation we perform. It will reset all the validation errors on this class and for all tags, so we can re validate whatever we need to.

    Returns void

    void

Generated using TypeDoc