nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Input don't add defaultValue in uncontrolled Input after form submit

Open J4v4Scr1pt opened this issue 1 year ago • 4 comments

NextUI Version

2.6.8

Describe the bug

After submitting an form and there are validation errors the response will put back input value using defaultValue prop. Following this video. When using NextUI Input component it clears no matter what. Using native input it works (or shadcn/ui as in video).

Your Example Website or App

https://codesandbox.io/p/devbox/nk4vk2

Steps to Reproduce the Bug or Issue

Start the project and test both the inputs

Expected behavior

That the default value to be set as with the native input

Screenshots or Videos

No response

Operating System Version

Window 11

Browser

Chrome

J4v4Scr1pt avatar Dec 23 '24 10:12 J4v4Scr1pt

A form reset happens when the form action property is used in this way. If you want to keep this form reset behavior, then this is an issue with RAC (see adobe/react-spectrum#6830). For potential ways to opt-out of the reset and still use React 19 hooks, see the discussion of the root issue.

Peterl561 avatar Dec 26 '24 05:12 Peterl561

A form reset happens when the form action property is used in this way. If you want to keep this form reset behavior, then this is an issue with RAC (see adobe/react-spectrum#6830). For potential ways to opt-out of the reset and still use React 19 hooks, see the discussion of the root issue.

Thanks for pointing me in the right direction ✌️. Not a big fan of the workarround tough, using onSubmit over action.

Thanks again!

Happy holidays 🎅🎆!

J4v4Scr1pt avatar Dec 26 '24 07:12 J4v4Scr1pt

A form reset happens when the form action property is used in this way. If you want to keep this form reset behavior, then this is an issue with RAC (see adobe/react-spectrum#6830). For potential ways to opt-out of the reset and still use React 19 hooks, see the discussion of the root issue.

Why can't we use input's defaultValue to set value from state when validation fails on server?

return {
    success: false,
    inputs: values
}
<Input defaultValue={state.inputs?.email ?? ""} />

Note that it works with native inputs.

obouchari avatar Mar 02 '25 22:03 obouchari