From 1e16b6ce43c456de1c55db836d2fcdc668e9c481 Mon Sep 17 00:00:00 2001 From: ggayane Date: Tue, 8 Nov 2016 14:40:00 +0400 Subject: [PATCH] propTypes changes --- README.md | 5 +- example/src/example.js | 109 ++++++++++++++++++++++++++++++++---- example/src/example.less | 2 +- example/src/index.html | 4 +- src/ReactInputValidation.js | 12 ++-- 5 files changed, 111 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 10d994f..2c80acb 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,4 @@ To build, watch and serve the examples (which will also watch the component sour ## License -__PUT LICENSE HERE__ - -Copyright (c) 2016 Gayane Gasparyan. - +[MIT] (https://github.com/Ggayane/react-input-validation/blob/master/license.md) diff --git a/example/src/example.js b/example/src/example.js index 0a794d3..d408156 100644 --- a/example/src/example.js +++ b/example/src/example.js @@ -1,16 +1,105 @@ -var React = require('react'); -var ReactDOM = require('react-dom'); -// var ReactInputValidation = require('react-input-validation'); +import React from 'react' +import ReactDOM from 'react-dom' +import FormInput from 'react-input-validation' +export default class App extends React.Component { + constructor () { + super() + this.state = { + email: '', + name: '', + age: '', + password: '', + re_password: '', + error: false, + btn_text: 'Check' + } + this._onChangeValue = this._onChangeValue.bind(this) + this.checkValidation = this.checkValidation.bind(this) + } + + _onChangeValue (prop, param) { + var state = {} + state[param] = prop.prop + this.setState(state) + } + + checkValidation () { + var error = false + if (this._isAllValuesTrue(this.refs)) { + var btn_text = 'Done!' + } else { + var btn_text = 'Not Valid!' + error = true + } + this.setState({ + error, + btn_text + }) + } + + _isAllValuesTrue (obj) { + return Object.keys(obj).every(elem => (typeof obj[elem].isValid === 'function' && obj[elem].isValid() === true)) + } -var App = React.createClass({ render () { - console.log('aaaaaa'); return ( -
- +
+
+ this._onChangeValue({prop}, 'email')} + validateType='email' + onKeyPress={this.handleKeyPress} + ref='email'/> + this._onChangeValue({prop}, 'name')} + validateType='required' + onKeyPress={this.handleKeyPress} + ref='name'/> + this._onChangeValue({prop}, 'age')} + validateType='onlyPositiveNumbers' + ref='age' /> + this._onChangeValue({prop}, 'password')} + passwordMinLength={6} + validateType='password' + onKeyPress={this.handleKeyPress} + ref='password' /> + this._onChangeValue({prop}, 're_password')} + validateType='re_password' + relValue={this.state.password || ''} + onKeyPress={this.handleKeyPress} + ref='re_password' /> + +
- ); + ) } -}); +} -ReactDOM.render(, document.getElementById('app')); +ReactDOM.render(, document.getElementById('app')) diff --git a/example/src/example.less b/example/src/example.less index 446e1cb..84403ac 100644 --- a/example/src/example.less +++ b/example/src/example.less @@ -1,4 +1,4 @@ -/* +/* // Examples Stylesheet // ------------------- */ diff --git a/example/src/index.html b/example/src/index.html index 3109c07..0d47d23 100644 --- a/example/src/index.html +++ b/example/src/index.html @@ -1,16 +1,16 @@ react-input-validation +

react-input-validation

View project on GitHub

- +

An example of react-input-validation using Bootstrap

-