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

Function setSubmissionErrors

packages/forms/signals/src/api/structure.ts:533–554  ·  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

531 * @param errors The errors to set.
532 */
533function setSubmissionErrors(
534 submittedField: FieldNode,
535 errors: OneOrMany<ValidationError.WithOptionalFieldTree>,
536) {
537 if (!isArray(errors)) {
538 errors = [errors];
539 }
540 const errorsByField = new Map<FieldNode, ValidationError.WithFieldTree[]>();
541 for (const error of errors) {
542 const errorWithField = addDefaultField(error, submittedField.fieldTree);
543 const field = errorWithField.fieldTree() as FieldNode;
544 let fieldErrors = errorsByField.get(field);
545 if (!fieldErrors) {
546 fieldErrors = [];
547 errorsByField.set(field, fieldErrors);
548 }
549 fieldErrors.push(errorWithField);
550 }
551 for (const [field, fieldErrors] of errorsByField) {
552 field.submitState.submissionErrors.set(fieldErrors);
553 }
554}

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