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

https://github.com/obss/react-validatable-form

React validatable form hook that is used to create dynamic client side validations on react forms
https://github.com/obss/react-validatable-form

hooks react validation validation-library validator

Last synced: 8 months ago
JSON representation

React validatable form hook that is used to create dynamic client side validations on react forms

Awesome Lists containing this project

README

          

# React Validatable Form

> React validatable form hook that is used to create dynamic client side validations on React forms.

examplegif

---

[![NPM (scoped)](https://img.shields.io/npm/v/react-validatable-form?label=npm%20%7C%20web)](https://www.npmjs.com/package/react-validatable-form)
[![License](https://img.shields.io/github/license/obss/react-validatable-form.svg)](https://github.com/obss/react-validatable-form/blob/master/LICENSE)
[![GitHub contributors](https://img.shields.io/github/contributors/obss/react-validatable-form)](https://github.com/obss/react-validatable-form/graphs/contributors)
[![Github Issues](https://img.shields.io/github/issues/obss/react-validatable-form.svg)](https://github.com/obss/react-validatable-form/issues)
[![Vulnerabilities](https://img.shields.io/snyk/vulnerabilities/github/obss/react-validatable-form)](https://github.com/obss/react-validatable-form)
[![Downloads](https://img.shields.io/npm/dw/react-validatable-form.svg)](https://www.npmjs.com/package/react-validatable-form)
[![Bundle Size](https://img.shields.io/bundlephobia/min/react-validatable-form)](https://www.npmjs.com/package/react-validatable-form)

---

## Table of Contents

- [Installation](#installation)

- [Getting Started](#getting-started)

- [Setup ReactValidatableFormProvider](#setup-reactvalidatableformprovider)
- [useValidatableForm Hook Usage](#usevalidatableform-hook-usage)

- [Examples](#examples)

- [Contributing](#contributing)

- [License](#license)

---

## Installation

**react-validatable-form** requires:

- React **17.0.2** or later

```shell

yarn add react-validatable-form

```

or

```shell

npm install react-validatable-form

```

## Getting Started

### Setup ReactValidatableFormProvider

Wrap your App inside `ReactValidatableFormProvider`.

```js
import { ReactValidatableFormProvider } from 'react-validatable-form';

// Wrap your app inside ReactValidatableFormProvider
const App = () => {
return (



);
};
```

### useValidatableForm Hook Usage

```js
import { useValidatableForm } from 'react-validatable-form';

const initialFormData = {};
const rules = [{ path: 'val', ruleSet: [{ rule: 'required' }] }];

const MyComponent = () => {
const { isValid, formData, setPathValue, setFormIsSubmitted, setPathIsBlurred, getValue, getError } =
useValidatableForm({
rules,
initialFormData,
});

return (
<>
setPathValue('val', e.target.value)}
onBlur={() => setPathIsBlurred('val')}
id="val"
/>

{getError('val') || ' '}


setFormIsSubmitted()}>Submit Form

>
);
};
```

## Examples

Checkout live examples on [react-validatable-form-demo](https://obss.github.io/react-validatable-form-demo) page for various customizations.

[Live Examples on StackBlitz](https://stackblitz.com/edit/react-validatable-form)

## Contributing

Please review the [contributing guide](https://github.com/obss/react-validatable-form/blob/master/CONTRIBUTING.md) before contributing to the repository.

## License

MIT

---