roqueform-external-errors-plugin
v0.0.2
Published
The plugin that associates external errors with Roqueform fields using adopters.
Downloads
28
Maintainers
Readme
roqueform-external-errors-plugin
The plugin that associates external errors with Roqueform fields using adopters.
npm install --save-prod roqueform roqueform-external-errors-plugin
Overview
Import and enable the plugin:
import { composePlugins, createField, errorsPlugin } from 'roqueform';
import { externalErrorsPlugin } from 'roqueform-external-errors-plugin';
const field = createField(
{ planet: 'Alderaan' },
composePlugins(
errorsPlugin(),
externalErrorsPlugin()
)
);
Declare how fields would adopt external errors:
field.at('planet').externalErrorAdopters = [
error => {
if (error.code === 'fictionalPlanet') {
return { message: 'Must be a real planet' };
}
}
];
Let fields adopt external errors:
const externalErrors = [{ code: 'fictionalPlanet' }];
field.adoptExternalErrors(externalErrors, { recursive: true });
field.at('planet').errors
// ⮕ [{ message: 'Must be a real planet' }]
field.at('planet').isInvalid
// ⮕ true