@ngx-formly/core 6.2.0 → 6.2.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.
@@ -532,16 +532,15 @@ class FormlyFormBuilder {
532
532
  }
533
533
  if (!field.parent) {
534
534
  this._setOptions(field);
535
- disableTreeValidityCall(field.form, () => {
536
- this._build(field);
535
+ }
536
+ disableTreeValidityCall(field.form, () => {
537
+ this._build(field);
538
+ if (!field.parent) {
537
539
  const options = field.options;
538
540
  options.checkExpressions?.(field, true);
539
541
  options.detectChanges?.(field);
540
- });
541
- }
542
- else {
543
- this._build(field);
544
- }
542
+ }
543
+ });
545
544
  }
546
545
  _build(field) {
547
546
  if (!field) {
@@ -814,6 +813,7 @@ class FormlyField {
814
813
  }
815
814
  triggerHook(name, changes) {
816
815
  if (name === 'onInit' || (name === 'onChanges' && changes.field && !changes.field.firstChange)) {
816
+ this.valueChangesUnsubscribe();
817
817
  this.valueChangesUnsubscribe = this.fieldChanges(this.field);
818
818
  }
819
819
  if (this.field?.hooks?.[name]) {
@@ -901,7 +901,6 @@ class FormlyField {
901
901
  this.componentRefs = [];
902
902
  }
903
903
  fieldChanges(field) {
904
- this.valueChangesUnsubscribe();
905
904
  if (!field) {
906
905
  return () => { };
907
906
  }
@@ -1291,7 +1290,7 @@ class FieldType {
1291
1290
  constructor() {
1292
1291
  this.field = {};
1293
1292
  }
1294
- set controls(controls) {
1293
+ set _formlyControls(controls) {
1295
1294
  const f = this.field;
1296
1295
  f._localFields = controls
1297
1296
  .map((c) => c.control._fields || [])
@@ -1331,10 +1330,10 @@ class FieldType {
1331
1330
  }
1332
1331
  }
1333
1332
  FieldType.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: FieldType, deps: [], target: i0.ɵɵFactoryTarget.Directive });
1334
- FieldType.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.12", type: FieldType, inputs: { field: "field" }, viewQueries: [{ propertyName: "controls", predicate: NgControl, descendants: true }], ngImport: i0 });
1333
+ FieldType.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.12", type: FieldType, inputs: { field: "field" }, viewQueries: [{ propertyName: "_formlyControls", predicate: NgControl, descendants: true }], ngImport: i0 });
1335
1334
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: FieldType, decorators: [{
1336
1335
  type: Directive
1337
- }], propDecorators: { controls: [{
1336
+ }], propDecorators: { _formlyControls: [{
1338
1337
  type: ViewChildren,
1339
1338
  args: [NgControl]
1340
1339
  }], field: [{
@@ -1483,6 +1482,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
1483
1482
  }] });
1484
1483
 
1485
1484
  class FieldWrapper extends FieldType {
1485
+ set _formlyControls(_) { }
1486
1486
  set _staticContent(content) {
1487
1487
  this.fieldComponent = content;
1488
1488
  }
@@ -1890,19 +1890,14 @@ class FieldValidationExtension {
1890
1890
  return (control) => {
1891
1891
  const errors = validatorOption.validation(control, field, validatorOption.options);
1892
1892
  if (isPromise(errors)) {
1893
- return errors.then((v) => this.handleAsyncResult(field, validatorName ? !!v : v, validatorOption));
1893
+ return errors.then((v) => this.handleResult(field, validatorName ? !!v : v, validatorOption));
1894
1894
  }
1895
1895
  if (isObservable(errors)) {
1896
- return errors.pipe(map((v) => this.handleAsyncResult(field, validatorName ? !!v : v, validatorOption)));
1896
+ return errors.pipe(map((v) => this.handleResult(field, validatorName ? !!v : v, validatorOption)));
1897
1897
  }
1898
1898
  return this.handleResult(field, validatorName ? !!errors : errors, validatorOption);
1899
1899
  };
1900
1900
  }
1901
- handleAsyncResult(field, errors, options) {
1902
- // workaround for https://github.com/angular/angular/issues/13200
1903
- field.options.detectChanges(field);
1904
- return this.handleResult(field, errors, options);
1905
- }
1906
1901
  handleResult(field, errors, { name, options }) {
1907
1902
  if (typeof errors === 'boolean') {
1908
1903
  errors = errors ? null : { [name]: options ? options : true };
@@ -2000,11 +1995,14 @@ class FieldFormExtension {
2000
1995
  markForCheck = true;
2001
1996
  }
2002
1997
  }
2003
- if (null === c.validator || null === c.asyncValidator) {
1998
+ if (null === c.validator && this.hasValidators(field, '_validators')) {
2004
1999
  c.setValidators(() => {
2005
2000
  const v = Validators.compose(this.mergeValidators(field, '_validators'));
2006
2001
  return v ? v(c) : null;
2007
2002
  });
2003
+ markForCheck = true;
2004
+ }
2005
+ if (null === c.asyncValidator && this.hasValidators(field, '_asyncValidators')) {
2008
2006
  c.setAsyncValidators(() => {
2009
2007
  const v = Validators.composeAsync(this.mergeValidators(field, '_asyncValidators'));
2010
2008
  return v ? v(c) : of(null);
@@ -2026,6 +2024,16 @@ class FieldFormExtension {
2026
2024
  }
2027
2025
  return markForCheck;
2028
2026
  }
2027
+ hasValidators(field, type) {
2028
+ const c = field.formControl;
2029
+ if (c?._fields?.length > 1 && c._fields.some((f) => f[type].length > 0)) {
2030
+ return true;
2031
+ }
2032
+ else if (field[type].length > 0) {
2033
+ return true;
2034
+ }
2035
+ return field.fieldGroup?.some((f) => f?.fieldGroup && !hasKey(f) && this.hasValidators(f, type));
2036
+ }
2029
2037
  mergeValidators(field, type) {
2030
2038
  const validators = [];
2031
2039
  const c = field.formControl;