@toolbox-web/grid-angular 0.16.0 → 0.16.1

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.
@@ -347,6 +347,7 @@ class GridFormArray {
347
347
  destroyRef = inject(DestroyRef);
348
348
  elementRef = inject((ElementRef));
349
349
  cellCommitListener = null;
350
+ cellCancelListener = null;
350
351
  rowCommitListener = null;
351
352
  touchListener = null;
352
353
  valueChangesSubscription = null;
@@ -410,6 +411,12 @@ class GridFormArray {
410
411
  this.#handleCellCommit(detail);
411
412
  };
412
413
  grid.addEventListener('cell-commit', this.cellCommitListener);
414
+ // Intercept cell-cancel events to revert FormControls (grid mode Escape)
415
+ this.cellCancelListener = (e) => {
416
+ const detail = e.detail;
417
+ this.#handleCellCancel(detail);
418
+ };
419
+ grid.addEventListener('cell-cancel', this.cellCancelListener);
413
420
  // Intercept row-commit events to prevent if FormGroup is invalid
414
421
  this.rowCommitListener = (e) => {
415
422
  if (!this.syncValidation())
@@ -445,6 +452,9 @@ class GridFormArray {
445
452
  if (this.cellCommitListener) {
446
453
  grid.removeEventListener('cell-commit', this.cellCommitListener);
447
454
  }
455
+ if (this.cellCancelListener) {
456
+ grid.removeEventListener('cell-cancel', this.cellCancelListener);
457
+ }
448
458
  if (this.rowCommitListener) {
449
459
  grid.removeEventListener('row-commit', this.rowCommitListener);
450
460
  }
@@ -684,6 +694,21 @@ class GridFormArray {
684
694
  event.preventDefault();
685
695
  }
686
696
  }
697
+ /**
698
+ * Handles cell-cancel events (grid mode Escape) — reverts the FormControl
699
+ * to the value it had before the edit session began.
700
+ */
701
+ #handleCellCancel(detail) {
702
+ const { rowIndex, field, previousValue } = detail;
703
+ const rowFormGroup = this.#getRowFormGroup(rowIndex);
704
+ if (rowFormGroup) {
705
+ const control = rowFormGroup.get(field);
706
+ if (control) {
707
+ control.setValue(previousValue, { emitEvent: false });
708
+ control.markAsPristine();
709
+ }
710
+ }
711
+ }
687
712
  /**
688
713
  * Syncs a FormControl's validation state to the grid's visual invalid styling.
689
714
  */