DoubleAgentValidator
This package serves as complement to the java library called doubleagentvalidator.
This is a javascript library which allow to reuse the same json schemas used in the backend rest application to validates the data at the frontend.
This libs depends on:
How to use:
1. Install the package in your application:
Recommended: Use yarn to install this package. This package manager will create
yarn.lock
file, to avoid broken packages caused bynpm
inconsistent versions.
# Install yarn package manager npm i -g yarn # Use yarn to install double-agent yarn install double-agent-validator
If you get the error PhantomJS not found on PATH
, just do that:
TMP_DIR=/tmp yarn install
Or use
npm
to install this package
npm i --save double-agent-validator
2. In your AppModule initialization inject a factory to get the validation script from the backend and fill-in the DoubleAgentValdiator service with the schemas, keywords and formats.
;;
Great!!! You just did it, now the following services are available on your Angular 2 App:
DoubleAgentValidatorService
This class allow you to validate some data in a service layer using its validate
method, which checks some data
againts an specific schema you pass to the service.
Your service will be something like the example bellow:
;;
DoubleAgentFormGroupBuilder
This class can be used to build FormGroup containing the controls representing each property in the schema including the respective validators.
Example:
;;
If you want create formGroup without validators because your application will handle the validation process itself, you can do this:
;;
TODO
-
Provide the service to allow error messages mapping
-
Website to share the library api documentation