Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AtLeastOneExistsRule

Validation rule that check that at least one of the object properties is not null.

see

IValidationRule

Example

let schema = new Schema()
    .withRule(new AtLeastOneExistsRule("field1", "field2"));

schema.validate({ field1: 1, field2: "A" });     // Result: no errors
schema.validate({ field1: 1 });                  // Result: no errors
schema.validate({ });                            // Result: at least one of properties field1, field2 must exist

Hierarchy

  • AtLeastOneExistsRule

Implements

Index

Constructors

Methods

Constructors

constructor

  • Creates a new validation rule and sets its values

    Parameters

    • Rest ...properties: string[]

      a list of property names where at least one property must exist

    Returns AtLeastOneExistsRule

Methods

validate

  • Validates a given value against this rule.

    Parameters

    • path: string

      a dot notation path to the value.

    • schema: Schema

      a schema this rule is called from

    • value: any

      a value to be validated.

    • results: ValidationResult[]

      a list with validation results to add new results.

    Returns void

Generated using TypeDoc