Higher-order component to validate a form field.
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
.babelrc
.eslintrc.js
.gitignore
LICENSE
README.md
demo.html
demo.jsx
package.json
prepare-gh-pages.js
webpack.config.js
webpack.demo.js
webpack.dev.js
webpack.prod.js
yarn.lock

README.md

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