question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reset form after submit

See original GitHub issue

Is 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:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
danielweinmanncommented, Jul 29, 2022

@gustavoguichard, I just created #69 based on @zolzaya’s suggestion. @zolzaya, is that what you had in mind?

1reaction
zolzayacommented, Jul 29, 2022

Thank for reply 😃 I make it work with below code. I replaced loading with submitting.

<Form 
  schema={schema}
  onTransition={
    ({transition, reset})  => {
      if(
        transition.state === 'submitting' &&
        transition.type === 'actionSubmission'
      ) {
        reset();
      }
    }
  }>
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found