Socket
Socket
Sign inDemoInstall

@lemoncode/fonk-array-required-validator

Package Overview
Dependencies
3
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @lemoncode/fonk-array-required-validator

This is a [fonk](https://github.com/Lemoncode/fonk) microlibrary that brings validation capabilities to validate if an array field of a form has items


Version published
Weekly downloads
9
decreased by-25%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

fonk-array-required-validator

CircleCI NPM Version bundle-size

This is a fonk microlibrary that brings validation capabilities to:

  • Validate if an array field of a form has items

How to install it:

npm install @lemoncode/fonk-array-required-validator --save

How to add it to an existing form validation schema:

We have the following form model:

const myFormValues = {
  product : 'shoes',
  price: 20,
  sizes: [36, 38, 41]
}

We can add a arrayRequired validation to the myFormValues

import { arrayRequired } from '@lemoncode/fonk-array-required-validator';

const validationSchema = {
  field: {
    sizes: [arrayRequired.validator],
  },
};

We must specify the minimum number (1 by default) and optionally the maximum number of items allowed:

import { arrayRequired } from '@lemoncode/fonk-array-required-validator';
const validationSchema = {
  field: {
    sizes: [
      {
        validator: arrayRequired.validator,
        customArgs: { minLength: 1, maxLength: 10 },
      },
    ],
  },
};

You can customize the error message displayed in two ways:

  • Globally, replace the default error message in all validationSchemas (e.g. porting to spanish):
import { arrayRequired } from '@lemoncode/fonk-array-required-validator';

arrayRequired.setErrorMessage('El campo debe de ser una lista');
  • Locally just override the error message for this validationSchema:
import { arrayRequired } from '@lemoncode/fonk-array-required-validator';

const validationSchema = {
  field: {
    price: [
      {
        validator: arrayRequired.validator,
        message: 'Error message only updated for the validation schema',
      },
    ],
  },
};

Please, refer to fonk to know more.

License

MIT

About Basefactor + Lemoncode

We are an innovating team of Javascript experts, passionate about turning your ideas into robust products.

Basefactor, consultancy by Lemoncode provides consultancy and coaching services.

Lemoncode provides training services.

For the LATAM/Spanish audience we are running an Online Front End Master degree, more info: http://lemoncode.net/master-frontend

Keywords

FAQs

Last updated on 05 Nov 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc