Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

submitData gets thrown away if onValid submit handler is used #149

Open
melanieseltzer opened this issue Jan 10, 2025 · 2 comments
Open
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@melanieseltzer
Copy link
Contributor

melanieseltzer commented Jan 10, 2025

Hi folks 👋

I am using the onValid submit handler in the following way (with a fetcher):

submitHandlers: {
  onValid: (data) => {
    const dirtyValues = getDirtyFormValues(data, dirtyFields);
    const formData = createFormData(dirtyValues);
    fetcher.submit(formData, {
      method: "POST",
    });
  },
},

I noticed that when I do this, it now no longer passes through extra values from submitData to the server on form submission 🤔

Looks like the merged payload gets thrown away when onValid is taking over.

Is that intentional? Could they just be merged into the data passed into the valid handler here? Or do I have to manually pass them myself in createFormData now in onValid (not use submitData anymore).

@AlemTuzlak
Copy link
Contributor

Hello! It is indeed intentional as I'd expect either that you have a valid onValid that you get the original data then do something with it and submit it in a custom way, or you just want to pass along a few fields to the submit and you don't want to use a custom one. I'd expect the dirtyValues here to be passed alongside your custom data into the fetcher.submit

@melanieseltzer
Copy link
Contributor Author

Thanks, that makes sense 👍 Just submitted a PR to add a small note about this in the readme docs, as maybe others could be surprised by this like I was.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants