Display onChange error messages in redux-form

I am trying to use a reduction form field (along with Material-ui) and validation. It seems that error messages are displayed when I move away from the field (i.e.OnBlur). What I would like to achieve is to do a check on the go, as a user, and display error messages in the Change event. How do I achieve this behavior?

import { TextField } from 'redux-form-material-ui';
import { Field, reduxForm } from 'redux-form';

const MyForm = (props) => (
  <form>
      <div className="form-group">
        <Field
          name="foo"
          type="text"
          hintText="Foo"
          component={TextField}
        />
  </form>
);

export default reduxForm({
  form: 'MyForm',  
  validate             
})(MyForm);
+4
source share
2 answers

Have you played with an example in CodeSandbox ? As Dennis suggested, you can call it “touch,” although you can do it onChange depending on your needs:

  <Field
    name="username"
    type="text"
    component={renderField}
    label="Username"
    onChange={() => touch('username')}
  />
+1
source

, (.. onBlur).

, , componentWillMount, mount:

componentWillMount() {
  const { touch } = this.props;
  touch('foo');
}

, , , , - , onChange .

+1

Source: https://habr.com/ru/post/1673431/


All Articles