0.0.3 • Published 6 years ago

react-validation-component v0.0.3

Weekly downloads
13
License
-
Repository
-
Last release
6 years ago

react validation component logo

React Validation Component is a utility component that solves data validation problem with the help of "native" React tool - prop-types.

Basic Example

Just show me the code!

import React, { Component } from 'react';
import ReactValidation from 'react-validation-component';
import PropTypes from 'prop-types';

class MyComponent extends Component{
  constructor(){
    super();

    this.state = { username: '', age: 0 };

    this.myForm = {
      username: PropTypes.string.isRequired
      age: PropTypes.number.isRequired
    };
  }

  onFormValidation(errors){
    // this method are going to be called on every validation
  }

  render(){
    const { username, age } = this.state;

    return <form>
      <ReactValidation propTypes={ this.myForm } onValidation={ this.onFormValidation.bind(this) }>{ this.state }</ReactValidation>

      <input name="username" value={ username } onChange={ e => this.setState({ username: e.target.value }) } />
      <input name="age" value={ age } onChange={ e => this.setState({ age: e.target.value }) } />
    </form>
  }
}
0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago