future/report: Updating a subset of fields #1096
Replies: 2 comments 4 replies
-
I am curious why you think this way. To me they are exactly the same. In fact, export async function action (request: Request) {
const formData = await request.formData();
const submission = parseSubmission(formData);
// This will deserialize the intent and update submission.value based on the intent
// e.g. intent.update('name', 'test') will result in `{ ...submission.value, name: 'test' }`
const [value, intent] = applyIntent(submission.value, submission.intent);
// Parse the updated value instead of submission.value
// as the error should always refers to the updated version
const result = schema.safeParse(value);
if (!result.success || intent) {
return report(submission, {
error: result.error,
// Send the updated value back to client so it is reflected there
targetValue: value,
});
}
// ...
} |
Beta Was this translation helpful? Give feedback.
-
|
Referring to it as different update mechanism was imprecise, my bad. 😅 What I meant was that the Operation 1: Reset all fields to current
Operation 2: Reset all fields to a new
Operation 3: Update single field, leaving others untouched
Operation 4: Update multiple fields, leaving others untouched
|
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.
-
If you have a form with a lot of fields, updating just one of them is possible using client-side JavaScript via
intent.update.However, if you're trying to update a single field through the server, you will find that the report API uses a different update mechanism.
Going through
report, you must either update every field (viareset: true, constructing a completetargetValueif desired) or none of them (by usingreportonly to pass validation errors to the UI).It would be useful if the
intentandreportAPIs were more similar to one another. This might also help get around some data races like #1095. The reason for that is that the point ofonInput={submitForm}is not primarily to update the field you're typing into, but usually to update dependent fields.Currently, the smallest API change enabling such behavior would be something like:
Beta Was this translation helpful? Give feedback.
All reactions