@esfaenza/forms-and-validations 15.2.50 → 15.2.52

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.
@@ -2622,13 +2622,39 @@ class FormAdaptiveComponent extends BaseFormControl {
2622
2622
  }
2623
2623
  break;
2624
2624
  }
2625
- pv._validator = pv.createValidator(pv.pattern);
2625
+ // A quanto pare la creazione del validatore rompe il caso d'uso classico...
2626
+ pv._validator = this.customPatternValidator(pv.pattern);
2626
2627
  this.ngControl._setValidators(validators);
2627
2628
  this.ngControl.control.setValidators(validators);
2628
2629
  this.ngControl.control.updateValueAndValidity();
2629
2630
  }
2630
2631
  super.ngOnInit();
2631
2632
  }
2633
+ /**
2634
+ * Validator that requires the control's value to match a regex pattern.
2635
+ * See `Validators.pattern` for additional information.
2636
+ */
2637
+ customPatternValidator(pattern) {
2638
+ if (!pattern)
2639
+ return (_) => null;
2640
+ let regex;
2641
+ let regexStr;
2642
+ if (typeof pattern === 'string') {
2643
+ regexStr = '';
2644
+ if (pattern.charAt(0) !== '^')
2645
+ regexStr += '^';
2646
+ regexStr += pattern;
2647
+ if (pattern.charAt(pattern.length - 1) !== '$')
2648
+ regexStr += '$';
2649
+ regex = new RegExp(regexStr);
2650
+ }
2651
+ return (control) => {
2652
+ if (!control.value) {
2653
+ return null;
2654
+ }
2655
+ return regex.test(this.floatValuePreAdjustmente) ? null : { 'pattern': { 'requiredPattern': regexStr, 'actualValue': this.floatValuePreAdjustmente } };
2656
+ };
2657
+ }
2632
2658
  /** @ignore */
2633
2659
  async ngOnChanges(changes) {
2634
2660
  const newSource = changes["Source"];
@@ -2785,8 +2811,10 @@ class FormAdaptiveComponent extends BaseFormControl {
2785
2811
  : JSON.parse(JSON.stringify(this.Model)))
2786
2812
  : null;
2787
2813
  if ((this.Type == "float" || this.Type == "number") && toEmit) {
2788
- if (this.AdjustNumber)
2814
+ if (this.AdjustNumber) {
2815
+ this.floatValuePreAdjustmente = toEmit;
2789
2816
  toEmit = toEmit.replace(".", "").replace(",", ".");
2817
+ }
2790
2818
  this.EvaluatedModel = toEmit;
2791
2819
  }
2792
2820
  else if (this.Type == "boolean") {