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 ( -
An example of react-input-validation using Bootstrap