MCPcopy Create free account
hub / github.com/angular/angular / setSubmissionErrors

Function setSubmissionErrors

packages/forms/signals/src/api/structure.ts:548–569  ·  view source on GitHub ↗

* 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.

(
  submittedField: FieldNode,
  errors: OneOrMany<ValidationError.WithOptionalFieldTree>,
)

Source from the content-addressed store, hash-verified

546 * @param errors The errors to set.
547 */
548function setSubmissionErrors(
549 submittedField: FieldNode,
550 errors: OneOrMany<ValidationError.WithOptionalFieldTree>,
551) {
552 if (!isArray(errors)) {
553 errors = [errors];
554 }
555 const errorsByField = new Map<FieldNode, ValidationError.WithFieldTree[]>();
556 for (const error of errors) {
557 const errorWithField = addDefaultField(error, submittedField.fieldTree);
558 const field = errorWithField.fieldTree() as FieldNode;
559 let fieldErrors = errorsByField.get(field);
560 if (!fieldErrors) {
561 fieldErrors = [];
562 errorsByField.set(field, fieldErrors);
563 }
564 fieldErrors.push(errorWithField);
565 }
566 for (const [field, fieldErrors] of errorsByField) {
567 field.submitState.submissionErrors.set(fieldErrors);
568 }
569}

Callers 1

submitFunction · 0.85

Calls 6

isArrayFunction · 0.90
addDefaultFieldFunction · 0.90
getMethod · 0.65
setMethod · 0.65
fieldTreeMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected