redux-form-with-ajv
This package combines redux-form with json-schema. It transforms the generated ajv errors to a way that redux-form can work with. As validation library it uses ajv.
The advanced usage give you more control about ajv itself, so you can pass your own instance of ajv maybe with plugins like ajv-errors
, ajv-keywords
, ajv-i18n (must be passed by localize option)
and so on, as well you have full control about the error via a callback.
Installation
npm install --save redux-form-with-ajv
Basic usage
; form: 'yourForm' validate: YourForm;
options
Advanced usage: ajv
option
Use your custom ajv instance via You can use ajv
option when you need full control of ajv. It is only mandatory to pass two options,
allErrors
and verbose
.
;; // Be sure to set the mandatory options!const ajv = allErrors: true verbose: true; form: 'yourForm' validate: YourForm;
localize
option with ajv-i18n
Localize error message via You can use localize
option to pass the translations from ajv-i18n.
;; form: 'yourForm' validate: YourForm;
errorMessage
option
Customize error message via You can use errorMessage
option to pass a function that will receive an ajv
error object as argument and should return error message.
; const errorMessage = { if errorkeyword === 'required' return 'is required'; return errormessage;}; form: 'yourForm' validate: YourForm;
View Sandbox Samples
Simple validation with few Field(s)
Dynamic validation with FieldArrays and custom error messages