From 59b37900318eb2d11aaa34361b2569cbe75dff84 Mon Sep 17 00:00:00 2001 From: Miles Malerba Date: Wed, 17 Dec 2025 12:55:18 -0800 Subject: [PATCH] refactor(forms): rename server errors to submission errors This better reflects the intent to indicate an error during submission, regardless of whether the error came from the server or not. (cherry picked from commit 244b54c9bfd82f868deedf490a1688003e3ff4f1) --- packages/forms/signals/src/api/structure.ts | 16 ++++++++-------- packages/forms/signals/src/field/submit.ts | 6 +++--- packages/forms/signals/src/field/validation.ts | 14 +++++++------- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/forms/signals/src/api/structure.ts b/packages/forms/signals/src/api/structure.ts index db339b11567..72b2b2cecd8 100644 --- a/packages/forms/signals/src/api/structure.ts +++ b/packages/forms/signals/src/api/structure.ts @@ -330,10 +330,10 @@ export function applyWhenValue( } /** - * Submits a given `FieldTree` using the given action function and applies any server errors - * resulting from the action to the field. Server errors returned by the `action` will be integrated + * Submits a given `FieldTree` using the given action function and applies any submission errors + * resulting from the action to the field. Submission errors returned by the `action` will be integrated * into the field as a `ValidationError` on the sub-field indicated by the `field` property of the - * server error. + * submission error. * * @example * ```ts @@ -356,7 +356,7 @@ export function applyWhenValue( * ``` * * @param form The field to submit. - * @param action An asynchronous action used to submit the field. The action may return server + * @param action An asynchronous action used to submit the field. The action may return submission * errors. * @template TModel The data type of the field being submitted. * @@ -378,19 +378,19 @@ export async function submit( node.submitState.selfSubmitting.set(true); try { const errors = await action(form); - errors && setServerErrors(node, errors); + errors && setSubmissionErrors(node, errors); } finally { node.submitState.selfSubmitting.set(false); } } /** - * Sets a list of server errors to their individual fields. + * Sets a list of submission errors to their individual fields. * * @param submittedField The field that was submitted, resulting in the errors. * @param errors The errors to set. */ -function setServerErrors( +function setSubmissionErrors( submittedField: FieldNode, errors: OneOrMany, ) { @@ -409,7 +409,7 @@ function setServerErrors( fieldErrors.push(errorWithField); } for (const [field, fieldErrors] of errorsByField) { - field.submitState.serverErrors.set(fieldErrors); + field.submitState.submissionErrors.set(fieldErrors); } } diff --git a/packages/forms/signals/src/field/submit.ts b/packages/forms/signals/src/field/submit.ts index bcbef034643..bbe7a515381 100644 --- a/packages/forms/signals/src/field/submit.ts +++ b/packages/forms/signals/src/field/submit.ts @@ -20,11 +20,11 @@ export class FieldSubmitState { */ readonly selfSubmitting = signal(false); - /** Server errors that are associated with this field. */ - readonly serverErrors: WritableSignal; + /** Submission errors that are associated with this field. */ + readonly submissionErrors: WritableSignal; constructor(private readonly node: FieldNode) { - this.serverErrors = linkedSignal({ + this.submissionErrors = linkedSignal({ source: this.node.structure.value, computation: () => [] as readonly ValidationError.WithField[], }); diff --git a/packages/forms/signals/src/field/validation.ts b/packages/forms/signals/src/field/validation.ts index 1a9f756eb50..936e471c6e1 100644 --- a/packages/forms/signals/src/field/validation.ts +++ b/packages/forms/signals/src/field/validation.ts @@ -38,8 +38,8 @@ export interface ValidationState { rawSyncTreeErrors: Signal; /** - * The full set of synchronous errors for this field, including synchronous tree errors and server - * errors. Server errors are considered "synchronous" because they are imperatively added. From + * The full set of synchronous errors for this field, including synchronous tree errors and submission + * errors. Submission errors are considered "synchronous" because they are imperatively added. From * the perspective of the field state they are either there or not, they are never in a pending * state. */ @@ -163,10 +163,10 @@ export class FieldValidationState implements ValidationState { }); /** - * The full set of synchronous errors for this field, including synchronous tree errors and server - * errors. Server errors are considered "synchronous" because they are imperatively added. From - * the perspective of the field state they are either there or not, they are never in a pending - * state. + * The full set of synchronous errors for this field, including synchronous tree errors and + * submission errors. Submission errors are considered "synchronous" because they are imperatively + * added. From the perspective of the field state they are either there or not, they are never in a + * pending state. */ readonly syncErrors: Signal = computed(() => { // Short-circuit running validators if validation doesn't apply to this field. @@ -177,7 +177,7 @@ export class FieldValidationState implements ValidationState { return [ ...this.node.logicNode.logic.syncErrors.compute(this.node.context), ...this.syncTreeErrors(), - ...normalizeErrors(this.node.submitState.serverErrors()), + ...normalizeErrors(this.node.submitState.submissionErrors()), ]; });