Caplin Trader 5.1.0

Class: module:ct-trading/validation/AbstractFieldValidator


The AbstractFieldValidator is a module:ct-trading/validation/Validator that makes it easy to write Validators that record information about errors in data that is structured as fields.
If validation errors are found, error objects are appended to the supplied module:ct-trading/validation/ValidationResult. These error objects take the form of maps with the field name as the key and the error message as a value. A map contains one or more key/value pairs. Each FieldValidator will only append one map to the ValidationResult, containing only the errors that were found within that validator.
Subclasses of AbstractFieldValidator must call the constructor in their constructor, and must implement module:ct-trading/validation/AbstractFieldValidator#validateField. This class is immutable. Its subclasses must be as well.


new module:ct-trading/validation/AbstractFieldValidator(fields)

Name Type Description
fields Array

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


if fields is not an array of strings.




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.

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.


(abstract) validateField(fieldValue) → {String}

Performs validation on the specified field according to rules in the implementing class and returns an error message if the field contains an error.

This method is abstract. Extending classes should implement this method to provide specific validation for a field value.

Name Type Description
fieldValue String

The field value to validate.


The error message that is associated with the field, or null if the field is not in error.