Skip to content

Commit 244b54c

Browse files
mmalerbaAndrewKushnir
authored andcommitted
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.
1 parent 3a32556 commit 244b54c

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

packages/forms/signals/src/api/structure.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ export function applyWhenValue(
330330
}
331331

332332
/**
333-
* Submits a given `FieldTree` using the given action function and applies any server errors
334-
* resulting from the action to the field. Server errors returned by the `action` will be integrated
333+
* Submits a given `FieldTree` using the given action function and applies any submission errors
334+
* resulting from the action to the field. Submission errors returned by the `action` will be integrated
335335
* into the field as a `ValidationError` on the sub-field indicated by the `field` property of the
336-
* server error.
336+
* submission error.
337337
*
338338
* @example
339339
* ```ts
@@ -356,7 +356,7 @@ export function applyWhenValue(
356356
* ```
357357
*
358358
* @param form The field to submit.
359-
* @param action An asynchronous action used to submit the field. The action may return server
359+
* @param action An asynchronous action used to submit the field. The action may return submission
360360
* errors.
361361
* @template TModel The data type of the field being submitted.
362362
*
@@ -378,19 +378,19 @@ export async function submit<TModel>(
378378
node.submitState.selfSubmitting.set(true);
379379
try {
380380
const errors = await action(form);
381-
errors && setServerErrors(node, errors);
381+
errors && setSubmissionErrors(node, errors);
382382
} finally {
383383
node.submitState.selfSubmitting.set(false);
384384
}
385385
}
386386

387387
/**
388-
* Sets a list of server errors to their individual fields.
388+
* Sets a list of submission errors to their individual fields.
389389
*
390390
* @param submittedField The field that was submitted, resulting in the errors.
391391
* @param errors The errors to set.
392392
*/
393-
function setServerErrors(
393+
function setSubmissionErrors(
394394
submittedField: FieldNode,
395395
errors: OneOrMany<ValidationError.WithOptionalField>,
396396
) {
@@ -409,7 +409,7 @@ function setServerErrors(
409409
fieldErrors.push(errorWithField);
410410
}
411411
for (const [field, fieldErrors] of errorsByField) {
412-
field.submitState.serverErrors.set(fieldErrors);
412+
field.submitState.submissionErrors.set(fieldErrors);
413413
}
414414
}
415415

packages/forms/signals/src/field/submit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ export class FieldSubmitState {
2020
*/
2121
readonly selfSubmitting = signal<boolean>(false);
2222

23-
/** Server errors that are associated with this field. */
24-
readonly serverErrors: WritableSignal<readonly ValidationError.WithField[]>;
23+
/** Submission errors that are associated with this field. */
24+
readonly submissionErrors: WritableSignal<readonly ValidationError.WithField[]>;
2525

2626
constructor(private readonly node: FieldNode) {
27-
this.serverErrors = linkedSignal({
27+
this.submissionErrors = linkedSignal({
2828
source: this.node.structure.value,
2929
computation: () => [] as readonly ValidationError.WithField[],
3030
});

packages/forms/signals/src/field/validation.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export interface ValidationState {
3838
rawSyncTreeErrors: Signal<ValidationError.WithField[]>;
3939

4040
/**
41-
* The full set of synchronous errors for this field, including synchronous tree errors and server
42-
* errors. Server errors are considered "synchronous" because they are imperatively added. From
41+
* The full set of synchronous errors for this field, including synchronous tree errors and submission
42+
* errors. Submission errors are considered "synchronous" because they are imperatively added. From
4343
* the perspective of the field state they are either there or not, they are never in a pending
4444
* state.
4545
*/
@@ -163,10 +163,10 @@ export class FieldValidationState implements ValidationState {
163163
});
164164

165165
/**
166-
* The full set of synchronous errors for this field, including synchronous tree errors and server
167-
* errors. Server errors are considered "synchronous" because they are imperatively added. From
168-
* the perspective of the field state they are either there or not, they are never in a pending
169-
* state.
166+
* The full set of synchronous errors for this field, including synchronous tree errors and
167+
* submission errors. Submission errors are considered "synchronous" because they are imperatively
168+
* added. From the perspective of the field state they are either there or not, they are never in a
169+
* pending state.
170170
*/
171171
readonly syncErrors: Signal<ValidationError.WithField[]> = computed(() => {
172172
// Short-circuit running validators if validation doesn't apply to this field.
@@ -177,7 +177,7 @@ export class FieldValidationState implements ValidationState {
177177
return [
178178
...this.node.logicNode.logic.syncErrors.compute(this.node.context),
179179
...this.syncTreeErrors(),
180-
...normalizeErrors(this.node.submitState.serverErrors()),
180+
...normalizeErrors(this.node.submitState.submissionErrors()),
181181
];
182182
});
183183

0 commit comments

Comments
 (0)