Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smikhalevski/roqueform-external-errors-plugin
The plugin that associates external errors with Roqueform fields using adopters.
https://github.com/smikhalevski/roqueform-external-errors-plugin
Last synced: 4 days ago
JSON representation
The plugin that associates external errors with Roqueform fields using adopters.
- Host: GitHub
- URL: https://github.com/smikhalevski/roqueform-external-errors-plugin
- Owner: smikhalevski
- License: mit
- Created: 2024-03-27T10:59:07.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-04-10T18:05:01.000Z (7 months ago)
- Last Synced: 2024-10-30T00:11:30.399Z (16 days ago)
- Language: TypeScript
- Homepage: https://smikhalevski.github.io/roqueform-external-errors-plugin/
- Size: 86.9 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# roqueform-external-errors-plugin
The plugin that associates external errors with [Roqueform](https://github.com/smikhalevski/roqueform#readme) fields
using adopters.```shell
npm install --save-prod roqueform roqueform-external-errors-plugin
```🔎 [Check out the API Docs](https://smikhalevski.github.io/roqueform-external-errors-plugin)
# Overview
Import and enable the plugin:
```ts
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:
```ts
field.at('planet').externalErrorAdopters = [
error => {
if (error.code === 'fictionalPlanet') {
return { message: 'Must be a real planet' };
}
}
];
```Let fields adopt external errors:
```ts
const externalErrors = [{ code: 'fictionalPlanet' }];field.adoptExternalErrors(externalErrors, { recursive: true });
field.at('planet').errors
// ⮕ [{ message: 'Must be a real planet' }]field.at('planet').isInvalid
// ⮕ true
```