ngx-eiffage-material 0.1.4 → 0.1.6

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.
@@ -7,7 +7,7 @@ import { MatIconModule } from '@angular/material/icon';
7
7
  import * as i2 from '@angular/material/progress-spinner';
8
8
  import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
9
9
  import * as i3$1 from '@angular/forms';
10
- import { FormControl, ReactiveFormsModule, NG_VALUE_ACCESSOR, NgControl, Validators, FormArray, FormGroup, FormBuilder, FormsModule } from '@angular/forms';
10
+ import { FormControl, ReactiveFormsModule, NG_VALUE_ACCESSOR, NgControl, FormGroupDirective, NgForm, Validators, FormArray, FormGroup, FormBuilder, FormsModule } from '@angular/forms';
11
11
  import * as i11 from '@angular/common';
12
12
  import { CommonModule, DatePipe, isPlatformBrowser, LowerCasePipe } from '@angular/common';
13
13
  import * as i2$1 from '@angular/material/chips';
@@ -597,6 +597,10 @@ class NgxBasicSelect {
597
597
  * y para no fallar cuando el componente se usa sin formulario.
598
598
  */
599
599
  _ngControl = inject(NgControl, { self: true, optional: true });
600
+ /** Formulario contenedor, para saber si ya se intentó enviar (reactive o template-driven). */
601
+ _parentFormGroup = inject(FormGroupDirective, { optional: true });
602
+ _parentForm = inject(NgForm, { optional: true });
603
+ _changeDetectorRef = inject(ChangeDetectorRef);
600
604
  // ─── Inputs ──────────────────────────────────────────────────────────────
601
605
  label = input.required(...(ngDevMode ? [{ debugName: "label" }] : []));
602
606
  options = input.required(...(ngDevMode ? [{ debugName: "options" }] : []));
@@ -673,9 +677,15 @@ class NgxBasicSelect {
673
677
  const count = this.resolvedOptions().filter(o => o.visible).length;
674
678
  return this.intl.getSearchResultsCountMessage(count);
675
679
  }, ...(ngDevMode ? [{ debugName: "searchAnnouncement" }] : []));
676
- /** ErrorStateMatcher que refleja el estado del control del formulario. */
680
+ /**
681
+ * ErrorStateMatcher que refleja el estado del control del formulario.
682
+ * Replica el criterio por defecto de Material: se muestra el error si el
683
+ * control es inválido y además ha sido tocado O ya se ha enviado el
684
+ * formulario. Sin la parte de `submitted`, al pulsar "Guardar" los campos
685
+ * obligatorios que el usuario no llegó a tocar no se marcaban en rojo.
686
+ */
677
687
  errorStateMatcher = {
678
- isErrorState: () => !!(this._ngControl?.invalid && this._ngControl?.touched),
688
+ isErrorState: () => !!(this._ngControl?.invalid && (this._ngControl?.touched || this._isParentFormSubmitted())),
679
689
  };
680
690
  /**
681
691
  * Obligatorio si el control del formulario tiene el validador `required`.
@@ -685,6 +695,10 @@ class NgxBasicSelect {
685
695
  isRequired() {
686
696
  return this._ngControl?.control?.hasValidator(Validators.required) ?? false;
687
697
  }
698
+ /** true cuando el formulario contenedor ya ha intentado enviarse. */
699
+ _isParentFormSubmitted() {
700
+ return this._parentFormGroup?.submitted || this._parentForm?.submitted || false;
701
+ }
688
702
  constructor() {
689
703
  // Auto-registro como CVA (evita el provider NG_VALUE_ACCESSOR y su DI circular).
690
704
  if (this._ngControl)
@@ -705,6 +719,17 @@ class NgxBasicSelect {
705
719
  this.onChange(value);
706
720
  this.selectionChange.emit(value);
707
721
  });
722
+ /**
723
+ * `submitted` del formulario padre es una propiedad normal, no una señal:
724
+ * al enviar, nada marca este componente (OnPush) para revisión, así que el
725
+ * mat-select no reevaluaba su errorStateMatcher y el campo no se pintaba en
726
+ * rojo. Al enviarse el formulario se fuerza la revisión.
727
+ */
728
+ const parentSubmit = this._parentFormGroup?.ngSubmit ?? this._parentForm?.ngSubmit;
729
+ parentSubmit?.pipe(takeUntilDestroyed()).subscribe(() => {
730
+ this.innerControl.markAsTouched();
731
+ this._changeDetectorRef.markForCheck();
732
+ });
708
733
  }
709
734
  // ─── ControlValueAccessor ─────────────────────────────────────────────────
710
735
  writeValue(value) {
@@ -3503,6 +3528,10 @@ class NgxPaginatedSelect {
3503
3528
  _bottomSheet = inject(MatBottomSheet);
3504
3529
  /** Se auto-registra como CVA (self/optional para leer validación y no fallar sin form). */
3505
3530
  _ngControl = inject(NgControl, { self: true, optional: true });
3531
+ /** Formulario contenedor, para saber si ya se intento enviar (reactive o template-driven). */
3532
+ _parentFormGroup = inject(FormGroupDirective, { optional: true });
3533
+ _parentForm = inject(NgForm, { optional: true });
3534
+ _changeDetectorRef = inject(ChangeDetectorRef);
3506
3535
  intl = inject(NgxTablesIntl);
3507
3536
  // ─── Inputs ────────────────────────────────────────────────────────────────
3508
3537
  /** Label that floats on the form field */
@@ -3594,8 +3623,12 @@ class NgxPaginatedSelect {
3594
3623
  remainingChipsCount = computed(() => Math.max(0, this._selectedItems().length - this.maxChipsDisplayed()), ...(ngDevMode ? [{ debugName: "remainingChipsCount" }] : []));
3595
3624
  /** ErrorStateMatcher que refleja el estado del control del formulario. */
3596
3625
  errorStateMatcher = {
3597
- isErrorState: () => !!(this._ngControl?.invalid && this._ngControl?.touched),
3626
+ isErrorState: () => !!(this._ngControl?.invalid && (this._ngControl?.touched || this._isParentFormSubmitted())),
3598
3627
  };
3628
+ /** true cuando el formulario contenedor ya ha intentado enviarse. */
3629
+ _isParentFormSubmitted() {
3630
+ return this._parentFormGroup?.submitted || this._parentForm?.submitted || false;
3631
+ }
3599
3632
  /**
3600
3633
  * Obligatorio si el control del formulario tiene el validador `required`.
3601
3634
  * Se propaga al input interno para que el mat-form-field pinte el asterisco,
@@ -3633,6 +3666,16 @@ class NgxPaginatedSelect {
3633
3666
  }
3634
3667
  untracked(() => this.emitChange(items));
3635
3668
  });
3669
+ /**
3670
+ * `submitted` del formulario padre es una propiedad normal, no una senal:
3671
+ * al enviar, nada marca este componente (OnPush) para revision, asi que el
3672
+ * control interno no reevaluaba su errorStateMatcher y el campo no se
3673
+ * pintaba en rojo. Al enviarse el formulario se fuerza la revision.
3674
+ */
3675
+ const parentSubmit = this._parentFormGroup?.ngSubmit ?? this._parentForm?.ngSubmit;
3676
+ parentSubmit?.pipe(takeUntilDestroyed()).subscribe(() => {
3677
+ this._changeDetectorRef.markForCheck();
3678
+ });
3636
3679
  }
3637
3680
  // ─── ControlValueAccessor ───────────────────────────────────────────────────
3638
3681
  writeValue(value) {