RFC: Submission APIs #354
Replies: 6 comments 24 replies
-
|
This looks interesting! I was thinking for hiding/augmenting submissions, maybe you can have two separate apis: // form schema is username & password
submission.rejectWith(sub => ({ username: sub.username })) // <-- hide password |
Beta Was this translation helpful? Give feedback.
-
|
Zod strips out unrecognized keys during parsing by default, so Maybe const schema = z.object({
username: z.string(),
password: z.string(),
});
export async function action({ request }: ActionArgs) {
const formData = await request.formData();
const submission = parse(formData, { schema });
if (!submission.value) {
return json(submission.reject();
}
const result = await save(submission.value);
if (!result.successful) {
return json(
submission.reject({
formError: ["Submission failed"],
})
);
}
return json(submission.accept({ schema: schema.omit({ password: true }) }));
// or .pick to explicitly define what you _do_ want to return
// return json(submission.accept({ schema: schema.pick({ username: true }) }));
} |
Beta Was this translation helpful? Give feedback.
-
|
Hi @edmundhung I'm using :
I have a type error for the Is it something that is still subject to change ? Thank a lot for all the work, v1 is very promising
|
Beta Was this translation helpful? Give feedback.
-
|
Hello, playing around with v1-pre5 and looking great! Had a question about the API Should the submission API allow for the returning of some arbitrary value? For example the result of a mutation. The type would have to specified as a generic argument to SubmissionResult but then I think could go something like this: So that we have access to it on the front end (via lastResult) Or would this not be generally needed? |
Beta Was this translation helpful? Give feedback.
-
|
Also- this is a separate issue so I'll leave a separate comment but I am having some issues with the I am playing around with v1-pre5 with Next 14 and its been going largely very well, but am running into some unexpected behavior with the form dirty state. So I have a form populated with some init values (requested on server at page.tsx level) and form.dirty correctly starts as What I want to happen is after a successful submission for form.dirty to go back to Using Any ideas? Let me know if youd like me to make a minimal repro Thanks |
Beta Was this translation helpful? Give feedback.
-
|
My grudge with the current design/proposal is that there is no way to communicate successful state message. I just want a simple way to communicate form-level (as opposed to input level) success/failure of the submission, e.g. return json(submission.reply({
status: {
type: 'success',
message: 'Password reset link sent to your email'
},
});return json(submission.reply({
status: {
type: 'error',
message: 'Incorrect email or password'
},
});At the moment, I have to add new top-level properties and it feels like I am working against the framework, e.g. return json({
...submission.reply(),
message: {
message: 'Password reset email sent.',
type: 'success' as const,
},
}); |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
RFC: Submission APIs
Status:
ProposedReleated:
Background
There are a few common questions when we parse the
FormDataon the server:For sure, we have an answer for all the questions above:
However, the DX (Developer Experience) is poor. We can have all these documented, but it is still hard to understand what each of these code snippet does, especially for beginners. It could also be error-prone if you are not familiar with the data structure of the
submissionobject.We need proper APIs to handle the submission on the server.
Proposal
Introducing an additional method to the
submissionobject:submission.reply().Beta Was this translation helpful? Give feedback.
All reactions