Caplin Trader 5.1.0

Class: module:ct-trading/validation/OneOfValidator

module:ct-trading/validation/OneOfValidator(fields, allowableValues)

The OneOfValidator is a module:ct-trading/validation/Validator that verifies that the specified field values are one of the allowed field values. This class is immutable.

Constructor

new module:ct-trading/validation/OneOfValidator(fields, allowableValues)

The constructor for the OneOfValidator.

Extends:
Parameters:
Name Type Description
fields Array

An array of string field names that must be present in the data to validate. Must not be null.

allowableValues Array

The allowed field values.

Throws:

if the list of fields is not an array of strings, or the allowed values is not an array of strings.

Type
module:ct-core/Error

Extends

Methods

validate(oDataToValidate, oValidationResult)

Validates the supplied data and adds an error map to the validation result if any of the fields are missing, or if the implementing validator deems that the field contains an error. The error object is a map with the field name as the key and the error as the value. Implementing classes should not override this method.

Parameters:
Name Type Description
oDataToValidate module:ct-trading/trademodel/DataHolder

The data to validate. Must not be null or undefined.

oValidationResult module:ct-trading/validation/ValidationResult

A module:ct-trading/validation/ValidationResult to which the error map is added. Must not be null or undefined.

Inherited From:

validateField(value) → {String}

Performs validation on the specified field to determine if it is one of the allowed field values.

Parameters:
Name Type Description
value String

The field value to validate.

Overrides:
Returns:

An error message indicating the validation failure, or null if no errors occurred.

Type
String