Skip to content

yupresolver doesnt fire all validation at once. #8

@activebiz

Description

@activebiz

The yup validation is not firing all validation at one go on the 'fullName' field.

import { useForm, Controller } from "react-hook-form";
import * as yup from "yup";
import { yupResolver } from "@hookform/resolvers";
import { TextField } from "@material-ui/core";
import "./styles.css";

const schema = yup.object().shape({
  name: yup
    .string()
    .min(3)
    .lowercase()
    .email()
    .required()
});

export default function App() {
  const { handleSubmit, control, errors } = useForm({
    resolver: yupResolver(schema)
  });
  const onSubmit = data => {
    console.log(data);
  };
  console.log(`on render errors: ${JSON.stringify(errors, null, 4)}`);
  return (
    <form onSubmit={handleSubmit(onSubmit)}>
      <Controller
        as={<TextField />}
        name="name"
        control={control}
        defaultValue=""
      />
      <button>Submit</button>
    </form>
  );
}

Here's CSB: https://codesandbox.io/s/competent-greider-8c8w8

Expected result: I was expecting multiple validation erros on name field.
Actual result: In contrast I can only get one validaiton error at a time.
image

I take abortEarly : false by default.

Any idea?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions