@esfaenza/forms-and-validations 15.2.22 → 15.2.23

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.
@@ -354,6 +354,10 @@ class BaseValidation {
354
354
  });
355
355
  }
356
356
  }
357
+ checkRequiredness(_validators) {
358
+ if (_validators && _validators.some(elem => elem instanceof RequiredValidator && (elem.required === true || (!elem.required && elem.required !== false))))
359
+ this.required = true;
360
+ }
357
361
  ngOnDestroy() {
358
362
  this.destroyed$.next();
359
363
  this.destroyed$.complete();
@@ -575,9 +579,7 @@ class ValidationSelectComponent extends BaseValidation {
575
579
  ngOnInit() {
576
580
  super.ngOnInit();
577
581
  this.registerFocusRequest();
578
- //controllo se è settato un required per decidere in maniera condizionale se utilizzare il validatore required nel componente interno
579
- if (this._validators && this._validators.some(elem => elem instanceof RequiredValidator))
580
- this.required = true;
582
+ this.checkRequiredness(this._validators);
581
583
  }
582
584
  /**
583
585
  * @ignore
@@ -726,9 +728,7 @@ class ValidationDateComponent extends BaseValidation {
726
728
  ngOnInit() {
727
729
  super.ngOnInit();
728
730
  this.registerFocusRequest();
729
- //controllo se è settato un required per decidere in maniera condizionale se utilizzare il validatore required nel componente interno
730
- if (this._validators && !this.noValidate && this._validators.some(elem => elem instanceof RequiredValidator))
731
- this.required = true;
731
+ this.checkRequiredness(this._validators);
732
732
  this._format = this.lc.token("getSmallDateDisplayFormat");
733
733
  }
734
734
  /**
@@ -929,9 +929,7 @@ class ValidationInputComponent extends BaseValidation {
929
929
  ngOnInit() {
930
930
  super.ngOnInit();
931
931
  this.registerFocusRequest();
932
- //controllo se è settato un required per decidere in maniera condizionale se utilizzare il validatore required nel componente interno
933
- if (this._validators && !this.noValidate && this._validators.some(elem => elem instanceof RequiredValidator))
934
- this.required = true;
932
+ this.checkRequiredness(this._validators);
935
933
  if (this.Password)
936
934
  this.type = "password";
937
935
  }
@@ -1252,9 +1250,7 @@ class ValidationDateTimeComponent extends BaseValidation {
1252
1250
  ngOnInit() {
1253
1251
  super.ngOnInit();
1254
1252
  this.registerFocusRequest();
1255
- // Controllo se è settato un required per decidere in maniera condizionale se utilizzare il validatore required nel componente interno
1256
- if (this._validators && !this.noValidate && this._validators.some(elem => elem instanceof RequiredValidator))
1257
- this.required = true;
1253
+ this.checkRequiredness(this._validators);
1258
1254
  this._format = this.lc.token("getSmallDateDisplayFormat");
1259
1255
  }
1260
1256
  /**
@@ -1414,9 +1410,7 @@ class ValidationAutocompleteComponent extends BaseValidation {
1414
1410
  ngOnInit() {
1415
1411
  super.ngOnInit();
1416
1412
  this.registerFocusRequest();
1417
- //controllo se è settato un required per decidere in maniera condizionale se utilizzare il validatore required nel componente interno
1418
- if (this._validators && !this.noValidate && this._validators.some(elem => elem instanceof RequiredValidator))
1419
- this.required = true;
1413
+ this.checkRequiredness(this._validators);
1420
1414
  }
1421
1415
  /** @ignore */
1422
1416
  ngOnDestroy() {
@@ -1554,9 +1548,7 @@ class ValidationAutocompleteMultiComponent extends BaseValidation {
1554
1548
  ngOnInit() {
1555
1549
  super.ngOnInit();
1556
1550
  this.registerFocusRequest();
1557
- //controllo se è settato un required per decidere in maniera condizionale se utilizzare il validatore required nel componente interno
1558
- if (this._validators && !this.noValidate && this._validators.some(elem => elem instanceof RequiredValidator))
1559
- this.required = true;
1551
+ this.checkRequiredness(this._validators);
1560
1552
  }
1561
1553
  /** @ignore */
1562
1554
  ngOnDestroy() {
@@ -1714,6 +1706,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.2.9", ngImpor
1714
1706
  args: [MatLegacyAutocompleteTrigger]
1715
1707
  }] } });
1716
1708
 
1709
+ // Angular
1717
1710
  /** Componente base da cui tutti i componenti Form implementano */
1718
1711
  class BaseFormControl {
1719
1712
  /**
@@ -1987,7 +1980,7 @@ class BaseFormControl {
1987
1980
  ngOnInit() {
1988
1981
  // A volte nell'ngOnInit non ci passa quindi lo metto sia qui sia nell'afterviewinit, penso che valga per i componenti di terze parti
1989
1982
  // che si collegano per i cazzi loro al form ecc, quindi la parte sopra non serve... BOH
1990
- this.checkRequiredValidator();
1983
+ this.checkRequiredness();
1991
1984
  //Il nome non c'è se metto standalone : true (CHE NON é DA METTERE)
1992
1985
  //Dato che anche il controllo esterno viene considerato come componente del form, non posso basarmi solo sul nome ma devo aggiungere un tag. In questo caso "_internal"
1993
1986
  // ATTENZIONE: QUALSIASI SIA IL MOTIVO, SE STO COSO VIENE SPOSTATO DALL ngOnInit NON FUNZIONA PIU NULLA
@@ -2032,17 +2025,18 @@ class BaseFormControl {
2032
2025
  this.destroyed$.complete();
2033
2026
  }
2034
2027
  /** Elabora i validatori iniettati e capisce se il valore è obbligatorio o meno */
2035
- checkRequiredValidator() {
2028
+ /** Fratello della funzione con lo stesso nome lato validations */
2029
+ checkRequiredness() {
2036
2030
  // controllo se è settato un required per decidere in maniera condizionale se utilizzare il validatore required nel componente interno
2037
2031
  // Lo faccio qui e non in un eventuale ngOnInit o costruttore perché ngOnInit non sempre viene chiamato e da costruttore il validatore non ha ancora il valore giusto
2038
- if (this._validators && this._validators.some(elem => elem.inputName == "required" && (elem.required === true || elem.required === null || elem.required === undefined)))
2032
+ if (this._validators && this._validators.some(elem => elem instanceof RequiredValidator && (elem.required === true || (!elem.required && elem.required !== false))))
2039
2033
  this.Required = true;
2040
2034
  }
2041
2035
  /** @ignore */
2042
2036
  ngAfterViewInit() {
2043
2037
  if (!this.ngControl)
2044
2038
  return;
2045
- this.checkRequiredValidator();
2039
+ this.checkRequiredness();
2046
2040
  }
2047
2041
  /** Helper che collega la funzione di reset del controllo form al controllo di validazione sottostante */
2048
2042
  bindResetFunction() {