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.

Filter out non-form data on reset

See original GitHub issue
interface FormData {
  greeting: string;
}

// in the component
reset({greeting: 'hello', otherProp: 'something else' });

const onSubmit = handleSubmit((formData) => {
  formData.otherProp ===  'something else' // true;
});

Ideally, reset would strip out any props that are not part of the form schema (in this case otherProp). I currently call reset when the data from the api has been returned. However, the data from the api contains all types of fields that are not part of the form schema. This becomes an issue since when I submit the formData to the api because I end up submitting additional data that I did not intend to submit. This becomes more of a problem with GraphQL since the server will actually reject requests that do not conform to the schema.

Describe the solution you’d like Ideally react-hook-form would only pick the properties that are part of the schema.

Describe alternatives you’ve considered I’m currently stripping the additional properties on my own.

btw, thank you for this amazing library. Working with forms in React has never been so easy 😃

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:16 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
bezreyhancommented, Jun 9, 2021

Just tried it and it is working perfectly. Thanks for the update!

1reaction
kodermaxcommented, May 21, 2021

up!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reset and submit form without empty values - Stack Overflow
If you truly want to reset the entire form, then use the basic JS .reset() . In your code, you can do this...
Read more >
Avoid clearing the data in form after submitting data using Patch
Check your gallery to ensure any filters don't filter out on success. Check the on success property of the form to ensure it...
Read more >
How to Prevent a Form from Clearing Fields on Submit
In JavaScript, you can use HTML forms for all sorts of purposes but these forms can sometimes g... ... Your browser can't play...
Read more >
Provided Filters - React Data Grid
'reset' : The Reset button will clear the details of the filter and any active filters on that column. 'cancel' : The Cancel...
Read more >
<input type="reset"> - HTML: HyperText Markup Language
Note: You should usually avoid including reset buttons in your forms. They're rarely useful, and are instead more likely to frustrate users ...
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