react-validation icon indicating copy to clipboard operation
react-validation copied to clipboard

validateAll() isn't finding anything

Open EricWVGG opened this issue 8 years ago • 2 comments

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.

EricWVGG avatar Oct 30 '17 17:10 EricWVGG

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.

dagi12 avatar Nov 28 '17 11:11 dagi12

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

rashmimhatre100 avatar May 08 '18 11:05 rashmimhatre100