Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/michaellasky/react-formguards

Simple, Declarative Client Side Form Validation
https://github.com/michaellasky/react-formguards

declarative form-validation javascript no-dependencies react reactjs

Last synced: 3 months ago
JSON representation

Simple, Declarative Client Side Form Validation

Awesome Lists containing this project

README

        

# react-formguards
> Simple, declarative, client side form validation - 2.5kb minzipped

[![NPM](https://img.shields.io/npm/v/react-formguards.svg)](https://www.npmjs.com/package/react-formguards) [![SIZE](https://img.shields.io/bundlephobia/minzip/react-formguards/latest.svg)](https://bundlephobia.com/result?p=react-formguards) [![Build Status](https://travis-ci.com/michaellasky/react-formguards.svg?branch=master)](https://travis-ci.com/michaellasky/react-formguards) [![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)

## The Problem

Client side form validation is a pain in the butt. Many solutions are complex, cumbersome, or both. Form validation should be simple.

## The Solution

react-formguards is powerful and very easy to use. Simple or complex validation rules can be declaratively defined with only <FormGuard /> tags. Just add FormGuards and you're done!

## Install

```bash
npm install --save react-formguards
```

## Usage

* Replace your <form /> tag with <ValidatedForm />, passing an onSubmit callback.
* *onSubmit is only called when all the FormGuard's are satisfied, which means the form is valid*

* Add <FormGuard /> tags anwhere you'd like validation errors to appear. The FormGuards handle everything else for you.

Check out the [Live Examples](https://michaellasky.github.io/react-formguards/) to see it in action!

See the [wiki](https://github.com/michaellasky/react-formguards/wiki) for further documentation.

```jsx
import { ValidatedForm, FormGuard, validators } from 'react-formguards'

const ExampleBasic = () => {

return (
console.log(formVals)}>
Name:

Email:

Email is required


Please enter a valid email address



Telephone:

Please enter a valid phone number

Comments:

Maximum length (80 characters) exceeded





);
}

export default ExampleBasic;
```

## License

MIT © [Michael Lasky](https://github.com/NuclearHorseStudios)

## Contributors

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

Michael Lasky
Michael Lasky

🚇 ⚠️ 📖 🚧 💻

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!