2,585 questions
2
votes
1
answer
62
views
React Hook Form does not upadate `errors` field on parent when triggering children
I have the following schema in my RHF form:
const latexSchema = z.string().refine(
() => {
return solutionRef.current?.editor?.state.doc.textContent.length! >= 10;
},
'Wymagane jest co ...
1
vote
1
answer
102
views
How to make part of a Zod schema optional only on submit?
I have a React project using TypeScript, React Hook Form, and Zod.
My Zod schema looks like this:
import { z } from 'zod';
export const loyaltyNmvFormSchema = z.object({
maxPoint: z.coerce.number()....
-2
votes
1
answer
117
views
z.input and z.output no different for zodResolver [closed]
I have a vector3d object
const vector3DBase = z
.object({
x: z.number().nullable(),
y: z.number().nullable(),
z: z.number().nullable(),
})
When added to a bigger schema
export const ...
174
votes
19
answers
318k
views
How to change React-Hook-Form defaultValue with useEffect()?
I am creating a page for user to update personal data with React-Hook-Form.
Once paged is loaded, I use useEffect to fetch the user's current personal data and set them into default value of the form.
...
0
votes
1
answer
68
views
React Hook Form add global on change before (or override setValue)
I have a schema like this:
const filterHomeworksSchema = z.object({
page: z.number(),
pageSize: z.number(),
search: z.string().optional(),
sort: selectItem.nullable(),
solutionFormats: ...
1
vote
1
answer
633
views
Shadcn, React-hook-form, Zod resolver throwing Runtime error when zod validation fails
I am using Shadcn Form which uses React-Hook-Form and Zod Resolver, The problem is when i submit the form by clicking the button while making the input incorrect for testing (Putting 1 char on 2 char ...
1
vote
1
answer
78
views
React Hook Form v7 onError callback not firing
I’m using React Hook Form v7 with handleSubmit(onSubmit, onError).
Here’s my form component:
function CreateCabinForm() {
const { register, handleSubmit, reset } = useForm();
function onSubmit(...
-1
votes
2
answers
122
views
React hook form + react query. Sync defaultValues on refetch without clobbering dirty fields, and hard-reset after submit [closed]
Context
I’m using React Hook Form together with React Query. The parent component fetches data with a query, derives defaultValues, and passes them into the form.
Parent component:
export const ...
2
votes
1
answer
519
views
Zod + react-hook-form: .default(false) still resolves as boolean | undefined as if it were.optional()
I am facing a type mismatch issue while using "zod" schema with useForm of "react-hook-form".
Resolver showing error for type mismatch. I set default value and not optional but ...
0
votes
0
answers
102
views
react-hook-form useFieldArray overrides the id fields
Before there was an option to change the autogenerated id field name with keyName config (in useFieldArray). In the latest version it's not possible to set keyName to something else. My question is. ...
1
vote
1
answer
96
views
Multi-step form only submits last step's values – how to preserve and submit all step values?
I'm building a reusable form component in React that supports both:
Simple (single-step) forms, and
Multi-step forms (each step has its own schema and inputs).
I'm using:
react-hook-form
Zod for ...
2
votes
2
answers
467
views
Type Error with Optional Fields in React Hook Form and Yup Schema
I'm encountering a problem while using React Hook Form with Yup for validation. I have a schema where some fields are optional, but I'm getting a type error related to the resolver.
Here's my Yup ...
1
vote
1
answer
112
views
How do I make a DatePicker get focused on submit, if the field is empty or giving errors?
I'm trying to use @mui/x-date-pickers: "^8.3.1 DatePicker component in a form with react-hook-form: "^7.62.0"
Using some workarounds, I managed to give errors on blur and on submit, but ...
3
votes
1
answer
4k
views
Error: Export useForm doesn't exist in target module
I am trying to use react-hook-form in my nextjs component with shadcnUI Form. But the error that I am having is :
Export useForm doesn't exist in target module
23 | FormMessage,
24 | } from "@/...
1
vote
1
answer
40
views
Yup conditional validation not receiving field value
I have a simple react-hook-form driven form that I'm conditionally validating with yup. I have a dropdown that, depending on the selected value, should change the required-ness of the following field.
...
1
vote
2
answers
2k
views
why isn't refine() / superrefine() working in zod with React Hook forms?
I am making a react application using vite, react hook form (7.54.1) and zod (3.24.1) whose main function is a multi step form. Now in my form schemas, I need to customize the default zod messages ...
10
votes
14
answers
31k
views
Shadcn Select is having issue with dynamically generated SelectItem
I am having an issue with Shadcn react library's Select component. It seems that "dynamically" generated SelectItem is causing an issue were they are not displayed in the SelectValue box ...
1
vote
1
answer
101
views
Should I split useWatch into individual calls to avoid unnecessary useEffect triggers in React Hook Form?
I'm using React Hook Form along with useWatch and useEffect. I’m currently watching multiple fields using a single useWatch call:
const [isRevolving, facilityGroup, facilities, payerGroupRates, ...
0
votes
1
answer
223
views
How to safely use useWatch with required nested object fields in yup schema without default values?
I'm using react-hook-form with yup for validation and type inference (InferType). I have a required nested object in the schema, but I'm not setting default values for it at form initialization (...
0
votes
1
answer
100
views
Type error in the shadcn/ui FormField component
My zod schema is:
export const CourseSchema = z.object({
title: requiredString.max(100, { error: 'The title must not be longer than 100 characters!' }),
briefDescription: requiredString.max(200, {
...
94
votes
6
answers
88k
views
Getting Uncaught TypeError: path.split is not a function in react
I'm trying to do validations for my form in react. I chose "react-hook-form" library. But I'm constantly getting error "Path.split is not a function. Even after using the default ...
67
votes
10
answers
195k
views
React hook form: How to can I use onChange on React Hook Form Version 7.0
Previously I used to write like this:
<input className="form-control" name="productImage" type='file' onChange={handleImageUpload} ref={register({ required: true })} />
...
0
votes
1
answer
79
views
Handle multiple types 'react-hook-form'
Currently I'm working in a component that has two children, each children has their specific components and their own form, the structure of the data is similar. I'm using react js with hook form to ...
0
votes
1
answer
461
views
useFormContext is null when using react-hook-form wrapped by shadcn
I'm using react-hook-form with a shadcn wrapper, and usually it works well. But in this particular component, I get this error on runtime, that useFormContext is null in my shadcn coponent.
<Form {....
2
votes
0
answers
134
views
How to conditionally validate nested object fields in Zod + React Hook Form only after form submission?
I'm using React Hook Form with Zod in a Next.js project, and I'm trying to validate a nested repetition field based on the selected repetition_type.
My problem is:
Validation runs immediately when ...
0
votes
0
answers
78
views
Fields are optional despite having a required property - How to handle it?
I am new to react-hook-form. My form schema is described below:
My name property is required. But, when I use spread syntax to create data as a payload to send to server, TypeScript always says that ...
6
votes
3
answers
5k
views
How to properly handle a number input with ReactJS Hook Form, Zod, and ShadCN UI while avoiding controlled/uncontrolled state issues
I’m working with a form in ReactJS using react-hook-form and Zod for validation, along with ShadCN UI for components. I have a number input field that I want to validate as a number. However, I'm ...
0
votes
1
answer
256
views
React Hook Form + Zod throws error but error state is empty
I’m trying to make a form, and it has never been this hard. I’ve never had a problem with this before, but right now it’s making me freak out.
I have this very simple code:
import { useForm } from &...
13
votes
3
answers
11k
views
TypeError: clone.weekday is not a function
I upgraded the Ant Design version from 4 to 5 and replaced Moment with Day.js, then encountered this error.
const {
field,
fieldState: { error },
} = useController({ name: name, control: ...
1
vote
0
answers
154
views
Unable to enter values in react-hook-form FieldArray with TanStack Table integration
I'm building a form with react-hook-form that includes a useFieldArray for system users, displayed in a TanStack Table. While I can add new users, I can't edit the "Employee Name" and "...
0
votes
1
answer
113
views
Recursively map through zod shape
I have react-hook-form and zod/v4 for forms. I define zod validation object, and pass it as resolver to useForm. zod marks all fields as required by default and could mark them as optional. I need to ...
0
votes
2
answers
963
views
Zod refine not displaying errors for optional array fields in react-hook-form
I'm using Zod with react-hook-form to validate a form where at least one of two fields (warehouses or clusters) must be provided. Both fields are optional arrays of strings. I'm using .refine to ...
48
votes
6
answers
94k
views
How to conditionally disable the submit button with react-hook-form?
Couldn't find a solution.
I'm using react-hook-form and I want to disable the submit button when the forms are empty and enable as long as all forms have atleast something written in them.
How would I ...
1
vote
0
answers
150
views
How to solve excessively deep and possibly infinite types when using zodResolver
I am creating a form using react-hook-form, zod and @hookform/resolvers. I want a single form where the user can select an option and, based on the option, different values are required. Here are my ...
25
votes
10
answers
48k
views
How to focus when an error occurs in react-hook-form Controller?
I am rendering a custom component using the Controller of react-hook-form.
If an error occurs when using register, focus is normal, but the Controller does not.
I was able to find a way to handle an ...
1
vote
1
answer
81
views
React Hook Form - setValue or field.onChange causes scroll to top on first trigger only
<Controller
name='acknowledged_by_nurse'
control={control}
render={({ field, fieldState }) => (
<Button
label="...
0
votes
1
answer
114
views
Blank page on the browser in my ReactJS app using React Hook Form
The browser shows me blank page and I see no error in the VS Code and terminal, but in the console, I see:
"Uncaught Error: Too many re-renders. React limits the number of renders to prevent an ...
87
votes
6
answers
103k
views
How to make react-hook-form work with multiple forms in one page?
I am using react-hook-form in my project and I have 2 totally separate forms, but when I submit one of the forms and if some fields in the other form is required I can't submit the current form, check ...
0
votes
2
answers
61
views
React DatePicker flashes inside React Hook Form Controller render prop
I'm using react-datepicker inside a Controller from react-hook-form. The component works, but I'm seeing a strange issue:
Every time I interact with the DatePicker (e.g., select a date), the component ...
0
votes
1
answer
59
views
How can I stop onBlur on tab change in react-hook-form?
<Controller
name={name}
control={control}
rules={
{
validate: (value) => {
if (rules.required) {
...
60
votes
8
answers
97k
views
Proper way to use react-hook-form Controller with Material UI Autocomplete
I am trying to use a custom Material UI Autocomplete component and connect it to react-hook-form.
TLDR: Need to use Material UI Autocomplete with react-hook-form Controller without defaultValue
My ...
0
votes
1
answer
180
views
Dynamic form in react-hook-form with automatic appending
I am struggling creating a dynamic form with react-hook-form's useFieldArry, that appends a new field/input whenever the last field element gets non-empty (so that the user do not have to care about ...
62
votes
4
answers
121k
views
DefaultValues of react-hook-form is not setting the values to the Input fields in React JS
I want to provide default values in the input field using react-hook-form. First I retrieve the user data from the API endpoint and then setting the state users to that user data. Then I pass the ...
0
votes
0
answers
351
views
Performance Issues in React Hook Form with watch() and Select dropdown
I’m using React Hook Form (RHF) for form handling and Yup for validation in my React app. I have a dynamic list of rows, each containing an Autocomplete component from Material-UI (MUI), along with ...
67
votes
7
answers
86k
views
A component is changing an uncontrolled Autocomplete to be controlled
Can you tell me that why I'm getting error "A component is changing an uncontrolled Autocomplete to be controlled.
Elements should not switch from uncontrolled to controlled (or vice versa).
...
2
votes
1
answer
2k
views
How to get sub-schema from zod object schema
I have a schema like this:
const schema = z.object({
name: z.string(),
email: z.string()
})
Later in the code, I want to validate just email. Is it possible to get somehow email schema like this: ...
0
votes
1
answer
101
views
Get error or property using useLense in react-hook-form
Using react-hook-form and try to be typescript compliant. I have a type:
export type Vector3D = {
x: number;
y: number;
z: number;
};
And my reusable component
function Vector3DComponent({ lens ...
0
votes
1
answer
57
views
Why is my form not preselecting the market value when editing a broker in React?
React Hook Form Select Not Showing Pre-selected Value When Editing
I have a React form using React Hook Form and shadcn/ui Select components. When I click "Edit" on a table row to edit a ...
34
votes
7
answers
56k
views
react-hook-form onSubmit not triggered
import React, { useState } from "react";
import FileBase64 from "react-file-base64";
import { useDispatch } from "react-redux";
import { makeStyles } from "@material-...
24
votes
3
answers
65k
views
Email validation with zod
I have an email input and i want to validate that the user entered a specific email "[email protected]" and if not to show specific error message "This email is not in our database". I ...