roqueform-external-errors-plugin
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

roqueform-external-errors-plugin

The plugin that associates external errors with Roqueform fields using adopters.

npm install --save-prod roqueform roqueform-external-errors-plugin

🔎 Check out the API Docs

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

Package Sidebar

Install

npm i roqueform-external-errors-plugin

Weekly Downloads

31

Version

0.0.2

License

MIT

Unpacked Size

12 kB

Total Files

6

Last publish

Collaborators

  • smikhalevski