Validator Service

1. Description

This service type is a regular angular service type that is decorated by the averos decorator @AverosValidator().
The validator service will act on the entities’ members by providing a fully customizable values validation.

Both synchronous and asynchronous validations are supported.

Averos validation service will make it easy to implement custom field validators and provide an instant feedback to the user on the validation progress.

Validators are manually implemented like any regular angular services. Averos users are kept free to name their Validator services along with their validation methods.

2. Validator Service Class Diagram

Below is the Averos Validator Service class diagram related to a custom validator service.

Below is a typescript implementation of a Validator service named CustomFieldValidatorService:

@Injectable({
  providedIn: 'root'
})
@AverosValidator()
export class CustomFieldValidatorService {
}

đźš© Field Validators should be decorated with @AverosValidator() so that the framework would enable member binding and member metadata initialization.

3. Synchronous Validation

Synchronous validations are validations that occurs in a synchronous way, without requesting other resources, services or asynchronous logics.
Validating characters’ pattern against a regular expression is one typical synchronous validation.

4. Asynchronous Validation

Asynchronous validations are validations that occurs in an asynchronous way; by either requesting remote resources, services or asynchronous logic.
The validation process execution will then depend on asynchronous actions and thus it will wait for all asynchronous responses in order to complete its execution.

The asynchronous validation service will automatically trigger a user notification while the validation is occurring, by showing either a progress bar or a spinner, in order to prevent the user from performing extra actions while the asynchronous validation process is ongoing.

Averos provide two user notification types while performing asynchronous validations:

  • A global application notification: this will disable the whole application while performing the asynchronous validation action by showing either a progress bar or a spinner.
  • A component inlined notification: this will only disable the entity field on which the asynchronous validation is happening by showing a progress spinner.

A typical use case of asynchronous validation would be to check whether a user name is already created while providing a new name in a create user use case.

🙋‍♂️ Please refer to the field validator within the view section so that you learn more about how to bind your validator to entity members.