Skip to content

Commit 03a19d8

Browse files
Merge pull request #9 from gokulakannant/feature/updates
Feature/updates
2 parents 52fe545 + d6840a5 commit 03a19d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2857
-399
lines changed

CHANGELOG.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Introduction
2+
3+
Documentation of React Form Input Validation API's for use of web developers validating React Forms.
4+
5+
## Changelog
6+
7+
All notable changes to React Form Input Validation APIs will be documented in this file.
8+
9+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
10+
11+
## [2.0.0] - 22/11/2019
12+
13+
### Added
14+
15+
- Added the following new API's
16+
- [`useRules`](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#userules)
17+
- [`registerAsync`](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#registerasync)
18+
- [`setAttributeFormatter`](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#setattributeformatter)
19+
- [`addEventListener`](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#addeventlistener)
20+
- [`removeEventListener`](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#removeeventlistener)
21+
- A new custom event is introduced to provide validated form data.
22+
- [`onformsubmit`](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#onformsubmit)
23+
- A custom attribute `data-async` introduced to denotes async validation form field.
24+
It should be mentioned in form field, if the form field has async validation. Refer [`registerAsync`](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#registerasync) API for more details.
25+
26+
### Modified
27+
28+
- API Documentation contents has improved.
29+
- More Code Sandbox examples are added in the API document.
30+
- Modified API name from `handleFieldsChange` to [`handleChangeEvent`](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#handlechangeevent).
31+
- Error message containing state `inputErrors` is renamed to `errors`.
32+
- Accessing error message in state is modified from `state.inputErrors.{form field name}.message` to `state.errors.{form field name}`.
33+
34+
### Removed
35+
36+
- [Contructor](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#constructor) arguments reduced.
37+
- Rules passing in consturctor is removed. And the alternate is [`useRules`](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#userules).
38+
- Handle submit callback in constructor removed. And the alternate is [`onformsubmit`](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/classes/reactforminputvalidation.html#onformsubmit) event.
39+
40+
## [1.0.1] - 14/11/2019
41+
42+
### Added
43+
44+
- A limited featured package has published.

README.md

Lines changed: 73 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# React Input Form Validation
22

3+
[![npm package](https://img.shields.io/npm/v/react-form-input-validation)](https://www.npmjs.com/package/react-form-input-validation)
34
[![Build Status](https://api.travis-ci.org/gokulakannant/react-form-input-validation.png?branch=master)](https://travis-ci.org/gokulakannant/react-form-input-validation)
45
[![GitHub license](https://img.shields.io/github/license/gokulakannant/react-form-input-validation.svg)](https://github.com/gokulakannant/react-form-input-validation/blob/master/LICENSE.md)
56

6-
A customized [validatorjs](https://www.npmjs.com/package/validatorjs) library to validate the react forms.
7+
A customized [validatorjs](https://www.npmjs.com/package/validatorjs) library to validate the react forms. It uses the [Controlled Components](https://reactjs.org/docs/forms.html#controlled-components) approach for validation.
78

89
* [Supported Rules](https://www.npmjs.com/package/validatorjs#available-rules) (It is supports all validatorjs rules)
9-
* [Documentation](https://gokulakannant.github.io/react-form-input-validation/index.html)
10+
* [Documentation](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/index.html)
1011
* [Demo](https://codesandbox.io/s/react-form-input-validation-demp-hyuju?fontsize=14&hidenavigation=1&theme=dark) (in CodeSandbox)
1112

1213
## Why use react-form-input-validation?
@@ -17,13 +18,29 @@ A customized [validatorjs](https://www.npmjs.com/package/validatorjs) library to
1718
* Readable and declarative validation rules which is inspired by laravel framework.
1819
* Error messages with multilingual support.
1920

21+
## Installation
22+
23+
To install the stable version:
24+
25+
Using [npm](https://www.npmjs.com/) as your package manager.
26+
27+
```bash
28+
npm install --save react-form-input-validation
29+
```
30+
31+
Using [yarn](https://yarnpkg.com/en/) as your package manager.
32+
33+
```bash
34+
yarn add react-form-input-validation
35+
```
36+
2037
## Usage
2138

22-
A example form has given below. View all available apis in [documentation](https://gokulakannant.github.io/react-form-input-validation/classes/reactformvalidator.html).
39+
A example form has given below. View all available apis in [documentation](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/index.html).
2340

2441
```js
2542
import React from "react";
26-
import ReactFormValidation from "react-form-input-validation";
43+
import ReactFormInputValidation from "react-form-input-validation";
2744

2845
class ValidationForm extends React.Component {
2946
constructor(props) {
@@ -34,19 +51,17 @@ class ValidationForm extends React.Component {
3451
email: "",
3552
phone_number: ""
3653
},
37-
inputErrors: {}
54+
errors: {}
3855
};
39-
this.form = new ReactFormValidation(
40-
this,
41-
{
56+
this.form = new ReactFormInputValidation(this);
57+
this.form.useRules({
4258
name: "required",
4359
email: "required|email",
4460
phone_number: "required|numeric|digits_between:10,12",
45-
},
46-
(fields) => {
47-
alert(JSON.stringify(fields));
48-
}
49-
);
61+
});
62+
this.form.onformsubmit = (fields) => {
63+
// Do you ajax calls here.
64+
}
5065
}
5166

5267
render() {
@@ -59,12 +74,12 @@ class ValidationForm extends React.Component {
5974
type="text"
6075
name="name"
6176
onBlur={this.form.handleBlurEvent}
62-
onChange={this.form.handleFieldsChange}
77+
onChange={this.form.handleChangeEvent}
6378
value={this.state.fields.name}
6479
/>
6580
</label>
6681
<label className="error">
67-
{this.state.inputErrors.name ? this.state.inputErrors.name.message : ""}
82+
{this.state.errors.name ? this.state.errors.name : ""}
6883
</label>
6984
</p>
7085

@@ -75,12 +90,12 @@ class ValidationForm extends React.Component {
7590
type="email"
7691
name="email"
7792
onBlur={this.form.handleBlurEvent}
78-
onChange={this.form.handleFieldsChange}
93+
onChange={this.form.handleChangeEvent}
7994
value={this.state.fields.email}
8095
/>
8196
</label>
8297
<label className="error">
83-
{this.state.inputErrors.email ? this.state.inputErrors.email.message : ""}
98+
{this.state.errors.email ? this.state.errors.email : ""}
8499
</label>
85100
</p>
86101

@@ -91,12 +106,12 @@ class ValidationForm extends React.Component {
91106
type="tel"
92107
name="phone_number"
93108
onBlur={this.form.handleBlurEvent}
94-
onChange={this.form.handleFieldsChange}
109+
onChange={this.form.handleChangeEvent}
95110
value={this.state.fields.phone_number}
96111
/>
97112
</label>
98113
<label className="error">
99-
{this.state.inputErrors.phone_number ? this.state.inputErrors.phone_number.message : ""}
114+
{this.state.errors.phone_number ? this.state.errors.phone_number : ""}
100115
</label>
101116
</p>
102117
<p>
@@ -117,13 +132,49 @@ Refer the below example to override the attribute name,
117132
type="text"
118133
name="name"
119134
onBlur={this.form.handleBlurEvent}
120-
onChange={this.form.handleFieldsChange}
135+
onChange={this.form.handleChangeEvent}
121136
value={this.state.fields.name}
122-
data-attribute-name="USER NAME"
137+
data-attribute-name="Username"
123138
/>
124139
```
125140

126-
The output will be like, "The USER NAME field is required.".
141+
The output will be like, "The Username field is required.".
142+
143+
## Supported form fields
144+
145+
|Form Fields and Attributes|Support By Library|
146+
| :-- |:--:|
147+
|text|&#x2611;|
148+
|password|&#x2611;|
149+
|email|&#x2611;|
150+
|url|&#x2611;|
151+
|number|&#x2611;|
152+
|checkbox|&#x2611;|
153+
|radio|&#x2611;|
154+
|search|&#x2611;|
155+
|tel|&#x2611;|
156+
|date|&#x2611;|
157+
|month|&#x2611;|
158+
|week|&#x2611;|
159+
|time|&#x2611;|
160+
|datetime-local|&#x2611;|
161+
|textarea|&#x2611;|
162+
|select|&#x2611;|
163+
|color|&#x2611;|
164+
|Combo Box Fields|&#x2611;|
165+
|file|&#x2612;|
166+
|range|&#x2612;|
167+
|image|&#x2612;|
168+
169+
The input types button, submit, reset, hidden are exceptional from the above list.
170+
171+
## Versions
172+
173+
Latest Version: 2.0.0. For more versions refer [VERSIONS.md](VERSIONS.md).
174+
175+
## Changelog
176+
177+
Recently Updated? Please read the [changelog](CHANGELOG.md).
127178

128179
## License
129180

VERSIONS.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# React Form Input Validation Versions
2+
3+
You can come back to this page and switch the version of the docs you're reading at any time.
4+
5+
## Stable versions
6+
7+
The most recent version is recommended in production.
8+
9+
|Versions|Documents|Releases|
10+
|--------|---------|--------|
11+
|v2.0.0|[Documentation](https://gokulakannant.github.io/react-form-input-validation/v2.0.0/index.html)|[Release notes](https://github.com/gokulakannant/react-form-input-validation/releases/tag/v2.0.0)|
12+
|v1.0.1|[Documentation](https://gokulakannant.github.io/react-form-input-validation/index.html)| |
13+
14+
## Versioning strategy
15+
16+
React Form Input Validation follows [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html). React Form Input Validation version numbers have three parts: major.minor.patch. The version number is incremented based on the level of change included in the release.
17+
18+
* **Major releases** contain significant new features, some but minimal developer assistance is expected during the update. When updating to a new major release, you may need to run update scripts, refactor code, run additional tests, and learn new APIs.
19+
* **Minor releases** contain important new features. Minor releases are fully backward-compatible; no developer assistance is expected during update, but you can optionally modify your apps and libraries to begin using new APIs, features, and capabilities that were added in the release.
20+
* **Patch releases** are low risk, contain bug fixes and small new features. No developer assistance is expected during update.

example/package-lock.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)