Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

A disabled input is missing from react-hook-form's submitted data

Errordisabled input value is undefined in handleSubmit

Short answer

react-hook-form treats a disabled field as having no value, so it returns undefined and leaves the field out of the data passed to handleSubmit. Built-in rules like required are skipped for it too. If users should see a value but not edit it, use readOnly instead of disabled.

  • Applies to react-hook-form 7.5x, React 19
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Log the data in handleSubmit and compare it with the fields on screen.

    const onSubmit = (data) => console.log(data);
  2. 2Match what you see, then jump to its fix

    1. 1Only the disabled field is missing or undefinedThe field is disabledFix
    2. 2A required rule never fires for the disabled fieldBuilt-in validation silently skipped on the disabled fieldFix

What does the error look like?

  • disabled input value is undefined in handleSubmit
  • field missing from the submitted data object

Cause 1 of 2

The field is disabled

1Check

Find disabled on the input or in the register options.

grep -rn "disabled" src/forms/

2Fix

Replace disabled with readOnly when you still need the value. Note that the useForm-level disabled option disables the whole form and all its inputs.

<input readOnly {...register("id")} />

3Verify

The value appears in the logged data.

// submit the form and read the console

Confirmed by react-hook-form.com

Did this fix it?

Cause 2 of 2

Built-in validation silently skipped on the disabled field

1Check

Rules such as required or minLength no longer apply once the field is disabled.

grep -rn "required" src/forms/

2Fix

Validate with a schema and check for undefined, or switch to readOnly.

// with a schema resolver
z.object({ id: z.string() })

3Verify

Submitting without a value now shows an error.

// submit the form

Confirmed by react-hook-form.com

Did this fix it?

How do I stop it coming back?

  • Use disabled only for fields that really should be absent from the data.
  • Test submit output whenever you toggle a field's editable state.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.