Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: required property doesn't work when valueAsNumber property is true #9661

Closed
1 task done
JuandaGarcia opened this issue Dec 24, 2022 · 1 comment
Closed
1 task done
Labels
regression Regression with code change

Comments

@JuandaGarcia
Copy link

JuandaGarcia commented Dec 24, 2022

Version Number

7.41.1

Codesandbox/Expo snack

https://codesandbox.io/s/pensive-edison-3kzj0m?file=/src/App.js

Steps to reproduce

  1. Go to https://codesandbox.io/s/pensive-edison-3kzj0m?file=/src/App.js
  2. Click on Submit button
  3. See error
import { useForm } from "react-hook-form";
import { useState } from "react";

export default function App() {
  const {
    register,
    handleSubmit,
    formState: { errors }
  } = useForm();
  const [data, setData] = useState();

  const onSubmit = handleSubmit((data) => {
    setData(JSON.stringify(data));
  });

  return (
    <>
      <span>{data}</span>
      <form onSubmit={onSubmit}>
        <p>{errors?.price?.message}</p>
        <input
          type="number"
          {...register("price", {
            required: {
              value: true,
              message: "The price is required."
            },
            valueAsNumber: true
          })}
        />
        <button>Submit</button>
      </form>
    </>
  );
}

image

Expected behaviour

image

What browsers are you seeing the problem on?

Chrome

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ilteoood
Copy link

ilteoood commented Dec 27, 2022

Hey @bluebill1049 are you planning to release this soon?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
regression Regression with code change
Projects
None yet
Development

No branches or pull requests

3 participants