with-validation

1.1.3 • Public • Published

with-validation

Higher-order component to validate a form field.

Description

WithValidation is a method that returns a React higher-order component. The new component has a single property, validators, that accepts either a single method or an array of methods. Each method is a validator that accepts a value and returns an empty string if the value is valid, or an error-message if the value is not valid.

If the value becomes invalid, WithValidation will render an error message with the class "error-message".

WithValidation can take a second, optional argument. The second argument is a React component that will override the default error message markup. It must have a property named "messages" that accepts an array of error messages or null. Use this if the default error-message markup is not adequate for your app's needs.

See ErrorMessage component in demo.jsx as an example.

Installation

npm install with-validation

or

yarn add with-validation

Usage

See demo.jsx

Demo

See demo page.

Author

Lawrence Siden
Westside Consulting LLC
Ann Arbor, MI
lsiden@gmail.com

Copyright

Lawrence Siden, 2017

License

MIT

Package Sidebar

Install

npm i with-validation

Weekly Downloads

0

Version

1.1.3

License

MIT

Last publish

Collaborators

  • lsiden