Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

About

Higher-order component to validate a form field.

Resources

License

Packages

No packages published