@angular/forms 21.1.0-next.4 → 21.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2010-2025 Google LLC. https://angular.dev/license
3
+ Copyright (c) 2010-2026 Google LLC. https://angular.dev/license
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @license Angular v21.1.0-next.4
3
- * (c) 2010-2025 Google LLC. https://angular.dev/
2
+ * @license Angular v21.1.0
3
+ * (c) 2010-2026 Google LLC. https://angular.dev/
4
4
  * License: MIT
5
5
  */
6
6
 
@@ -616,7 +616,7 @@ class FieldValidationState {
616
616
  if (this.shouldSkipValidation()) {
617
617
  return [];
618
618
  }
619
- return [...this.node.logicNode.logic.syncErrors.compute(this.node.context), ...this.syncTreeErrors(), ...normalizeErrors(this.node.submitState.serverErrors())];
619
+ return [...this.node.logicNode.logic.syncErrors.compute(this.node.context), ...this.syncTreeErrors(), ...normalizeErrors(this.node.submitState.submissionErrors())];
620
620
  }, ...(ngDevMode ? [{
621
621
  debugName: "syncErrors"
622
622
  }] : []));
@@ -789,7 +789,7 @@ class FieldMetadataState {
789
789
  if (this.has(key)) {
790
790
  if (!this.metadata.has(key)) {
791
791
  if (key.create) {
792
- throw Error('Managed metadata cannot be created lazily');
792
+ throw new _RuntimeError(1912, ngDevMode && 'Managed metadata cannot be created lazily');
793
793
  }
794
794
  const logic = this.node.logicNode.logic.getMetadata(key);
795
795
  this.metadata.set(key, computed(() => logic.compute(this.node.context)));
@@ -1138,12 +1138,12 @@ class FieldSubmitState {
1138
1138
  selfSubmitting = signal(false, ...(ngDevMode ? [{
1139
1139
  debugName: "selfSubmitting"
1140
1140
  }] : []));
1141
- serverErrors;
1141
+ submissionErrors;
1142
1142
  constructor(node) {
1143
1143
  this.node = node;
1144
- this.serverErrors = linkedSignal({
1144
+ this.submissionErrors = linkedSignal({
1145
1145
  ...(ngDevMode ? {
1146
- debugName: "serverErrors"
1146
+ debugName: "submissionErrors"
1147
1147
  } : {}),
1148
1148
  source: this.node.structure.value,
1149
1149
  computation: () => []
@@ -1178,6 +1178,14 @@ class FieldNode {
1178
1178
  this.metadataState = new FieldMetadataState(this);
1179
1179
  this.submitState = new FieldSubmitState(this);
1180
1180
  }
1181
+ focusBoundControl() {
1182
+ this.getBindingForFocus()?.focus();
1183
+ }
1184
+ getBindingForFocus() {
1185
+ const own = this.formFieldBindings().filter(b => b.focus !== undefined).reduce(firstInDom, undefined);
1186
+ if (own) return own;
1187
+ return this.structure.children().map(child => child.getBindingForFocus()).reduce(firstInDom, undefined);
1188
+ }
1181
1189
  pendingSync = linkedSignal({
1182
1190
  ...(ngDevMode ? {
1183
1191
  debugName: "pendingSync"
@@ -1236,8 +1244,8 @@ class FieldNode {
1236
1244
  get readonly() {
1237
1245
  return this.nodeState.readonly;
1238
1246
  }
1239
- get fieldBindings() {
1240
- return this.nodeState.fieldBindings;
1247
+ get formFieldBindings() {
1248
+ return this.nodeState.formFieldBindings;
1241
1249
  }
1242
1250
  get submitting() {
1243
1251
  return this.submitState.submitting;
@@ -1347,6 +1355,12 @@ const EMPTY = computed(() => [], ...(ngDevMode ? [{
1347
1355
  const FALSE = computed(() => false, ...(ngDevMode ? [{
1348
1356
  debugName: "FALSE"
1349
1357
  }] : []));
1358
+ function firstInDom(a, b) {
1359
+ if (!a) return b;
1360
+ if (!b) return a;
1361
+ const position = a.element.compareDocumentPosition(b.element);
1362
+ return position & Node.DOCUMENT_POSITION_PRECEDING ? b : a;
1363
+ }
1350
1364
 
1351
1365
  class FieldNodeState {
1352
1366
  node;
@@ -1368,8 +1382,8 @@ class FieldNodeState {
1368
1382
  markAsUntouched() {
1369
1383
  this.selfTouched.set(false);
1370
1384
  }
1371
- fieldBindings = signal([], ...(ngDevMode ? [{
1372
- debugName: "fieldBindings"
1385
+ formFieldBindings = signal([], ...(ngDevMode ? [{
1386
+ debugName: "formFieldBindings"
1373
1387
  }] : []));
1374
1388
  constructor(node) {
1375
1389
  this.node = node;
@@ -1540,12 +1554,12 @@ async function submit(form, action) {
1540
1554
  node.submitState.selfSubmitting.set(true);
1541
1555
  try {
1542
1556
  const errors = await action(form);
1543
- errors && setServerErrors(node, errors);
1557
+ errors && setSubmissionErrors(node, errors);
1544
1558
  } finally {
1545
1559
  node.submitState.selfSubmitting.set(false);
1546
1560
  }
1547
1561
  }
1548
- function setServerErrors(submittedField, errors) {
1562
+ function setSubmissionErrors(submittedField, errors) {
1549
1563
  if (!isArray(errors)) {
1550
1564
  errors = [errors];
1551
1565
  }
@@ -1561,7 +1575,7 @@ function setServerErrors(submittedField, errors) {
1561
1575
  fieldErrors.push(errorWithField);
1562
1576
  }
1563
1577
  for (const [field, fieldErrors] of errorsByField) {
1564
- field.submitState.serverErrors.set(fieldErrors);
1578
+ field.submitState.submissionErrors.set(fieldErrors);
1565
1579
  }
1566
1580
  }
1567
1581
  function schema(fn) {
@@ -1574,5 +1588,5 @@ function markAllAsTouched(node) {
1574
1588
  }
1575
1589
  }
1576
1590
 
1577
- export { BasicFieldAdapter, DEBOUNCER, FieldNode, FieldNodeState, FieldNodeStructure, FieldPathNode, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MetadataKey, MetadataReducer, PATTERN, REQUIRED, addDefaultField, apply, applyEach, applyWhen, applyWhenValue, assertPathIsCurrent, calculateValidationSelfStatus, createManagedMetadataKey, createMetadataKey, form, getInjectorFromOptions, isArray, metadata, normalizeFormArgs, schema, submit };
1591
+ export { BasicFieldAdapter, DEBOUNCER, FieldNode, FieldNodeState, FieldNodeStructure, FieldPathNode, MAX, MAX_LENGTH, MIN, MIN_LENGTH, MetadataKey, MetadataReducer, PATTERN, REQUIRED, addDefaultField, apply, applyEach, applyWhen, applyWhenValue, assertPathIsCurrent, calculateValidationSelfStatus, createManagedMetadataKey, createMetadataKey, form, getInjectorFromOptions, metadata, normalizeFormArgs, schema, submit };
1578
1592
  //# sourceMappingURL=_structure-chunk.mjs.map