Reset form after submit
See original GitHub issueIs there any way to reset form after submitted?
I tried following way but no luck 😦
export default function AccountsIndexPage() {
const data = useLoaderData<LoaderData>();
let transition = useTransition();
let isAdding = transition.state === "submitting";
let formRef = useRef<HTMLFormElement>(null);
useEffect(() => {
if(!isAdding) {
formRef.current?.reset();
}
}, [isAdding]);
return (
<Panel>
<DataTable>
<Form schema={schema} ref={formRef} className="valid-form flex flex-wrap flex-row -mx-4 mb-6" id="account-form">
{({ Field, Errors, Button, register }) => (
....
In my console I get following errors:
react-dom.development.js:86 Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
Check the render method of `AccountsIndexPage`.
at Form3
at div
at div
at div
at div
at div
at div
at DataTable (http://localhost:5000/build/_shared/chunk-6HY25IE3.js:878:22)
at div
at Panel (http://localhost:5000/build/_shared/chunk-6HY25IE3.js:847:18)
at AccountsIndexPage (http://localhost:5000/build/routes/dashboard/organization/accounts/index-2NPI7QXN.js:56:16)
at RemixRoute (http://localhost:5000/build/_shared/chunk-3WT6HRTL.js:2552:3)
at Outlet (http://localhost:5000/build/_shared/chunk-3WT6HRTL.js:675:26)
Is there any option to automatically reset form after submitted ?
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Clearing my form inputs after submission - Stack Overflow
since you are using jquery library, i would advise you utilize the reset() method.
Read more >Clear Input fields after Submit using JavaScript | bobbyhadz
Clear all form fields after submitting # · Add a submit event listener on the form element. · When the form is submitted,...
Read more >HTML DOM Form reset() Method - W3Schools
The reset() method resets the values of all elements in a form (same as clicking the Reset button). Tip: Use the submit() method...
Read more >How to clear form after submit in Javascript without using reset?
In this code, we are using submit in type by which our form will get submitted but to make it free from the...
Read more >Reset HTML Form After Submission - Simple Examples
This quick beginner's tutorial will walk through how to reset an HTML form after submission. Free example source code download included.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gustavoguichard, I just created #69 based on @zolzaya’s suggestion. @zolzaya, is that what you had in mind?
Thank for reply 😃 I make it work with below code. I replaced
loading
withsubmitting
.