react-validation
react-validation copied to clipboard
validateAll() isn't finding anything
Unsure if this is the same issue others are having with React 16.
import React, { Component } from 'react';
import Form from 'react-validation/build/form'
import Input from 'react-validation/build/input';
const required = (value, props) => {
console.log('check', value, props)
if (!value || (props.isCheckable && !props.checked)) {
console.log('fail')
return <span className="form-error is-visible">Required</span>;
}
console.log('win')
};
class TestForm extends Component {
handleClick = () => {
console.log(this.form.getValues()) // will succesfully output {test: ""}
this.form.validateAll();
};
render() {
return (
<Form ref={c => { this.form = c }} onSubmit={this.handleSubmit} >
<button className="button" type="button" onClick={this.handleClick}>Validate all</button>
<Input type='text' name='test' validations={[required]}/>
</Form>
)
}
}
export default function MyForm() {
return (<TestForm/>)
}
If the input is left blank, clicking the button will output {test: ""}, so I know it's at least seeing the Input(s). The console commands in required() don't fire at all.
Any updates on this? Problem make this library completely useless.
edit: Ok, after some digging I found that I have to update React to 16. This should be written with big bolded letters on the very beggining of docs.
Updated react and it is working now, thank you so much. One can update react link using,
npm install --save react@^16.0.0 react-dom@^16.0.0