diff --git a/src/core/json-schema/src/formly-json-schema.service.spec.ts b/src/core/json-schema/src/formly-json-schema.service.spec.ts index 54ee6e6c5..e1966fb82 100644 --- a/src/core/json-schema/src/formly-json-schema.service.spec.ts +++ b/src/core/json-schema/src/formly-json-schema.service.spec.ts @@ -162,7 +162,6 @@ describe('Service: FormlyJsonschema', () => { defaultValue: undefined, templateOptions: { ...emmptyTemplateOptions }, fieldArray: childConfig, - fieldGroup: [], }; expect(config).toEqual(baseConfig); @@ -184,10 +183,11 @@ describe('Service: FormlyJsonschema', () => { expect(config.type).toEqual('array'); expect(config.fieldArray).toEqual(childConfig); + expect(config.fieldGroup).toBeUndefined(); // TODO: is this the best way to test this? // artificially increase the length of the fieldGroup // since the getter that is defined is based on that. - config.fieldGroup.push(null); + config.fieldGroup = [null]; expect(config.fieldArray).toEqual(childConfig2); config.fieldGroup.push(null); expect(config.fieldArray).toEqual({}); @@ -213,7 +213,7 @@ describe('Service: FormlyJsonschema', () => { // TODO: is this the best way to test this? // artificially increase the length of the fieldGroup // since the getter that is defined is based on that. - config.fieldGroup.push(null); + config.fieldGroup = [null]; expect(config.fieldArray).toEqual(childConfig2); config.fieldGroup.push(null); // should return the additional items schema when the fieldGroup's length @@ -635,7 +635,6 @@ describe('Service: FormlyJsonschema', () => { type: 'array', defaultValue: undefined, templateOptions: emmptyTemplateOptions, - fieldGroup: [], fieldArray: jasmine.any(Object) as any, }; diff --git a/src/core/json-schema/src/formly-json-schema.service.ts b/src/core/json-schema/src/formly-json-schema.service.ts index 359252fd7..efe68db24 100644 --- a/src/core/json-schema/src/formly-json-schema.service.ts +++ b/src/core/json-schema/src/formly-json-schema.service.ts @@ -182,7 +182,6 @@ export class FormlyJsonschema { // TODO: remove isEnum check once adding an option to skip extension if (!this.isEnum(schema)) { - field.fieldGroup = []; Object.defineProperty(field, 'fieldArray', { get: () => { if (!Array.isArray(schema.items)) { @@ -190,8 +189,9 @@ export class FormlyJsonschema { return this._toFieldConfig( schema.items, options); } - const itemSchema = schema.items[field.fieldGroup.length] - ? schema.items[field.fieldGroup.length] + const length = field.fieldGroup ? field.fieldGroup.length : 0; + const itemSchema = schema.items[length] + ? schema.items[length] : schema.additionalItems; return itemSchema diff --git a/src/core/src/lib/extensions/field-form/field-form.ts b/src/core/src/lib/extensions/field-form/field-form.ts index 753cd4c90..afdfbbee3 100644 --- a/src/core/src/lib/extensions/field-form/field-form.ts +++ b/src/core/src/lib/extensions/field-form/field-form.ts @@ -7,11 +7,6 @@ import { registerControl } from './utils'; /** @experimental */ export class FieldFormExtension implements FormlyExtension { onPopulate(field: FormlyFieldConfigCache) { - // TODO: add an option to skip extension - if (field.fieldArray) { - return; - } - if (field.key) { this.addFormControl(field); } diff --git a/src/core/src/lib/templates/field-array.type.ts b/src/core/src/lib/templates/field-array.type.ts index b048d4f27..2432f5a27 100644 --- a/src/core/src/lib/templates/field-array.type.ts +++ b/src/core/src/lib/templates/field-array.type.ts @@ -3,7 +3,7 @@ import { FormArray } from '@angular/forms'; import { FieldType } from './field.type'; import { clone, isNullOrUndefined, assignModelValue, getKeyPath } from '../utils'; import { FormlyFormBuilder } from '../services/formly.form.builder'; -import { FormlyFieldConfig, FormlyFieldConfigCache } from '../components/formly.field.config'; +import { FormlyFieldConfig } from '../components/formly.field.config'; import { FORMLY_CONFIG, FormlyExtension } from '../services/formly.config'; import { registerControl, unregisterControl } from '../extensions/field-form/utils'; @@ -22,6 +22,10 @@ export abstract class FieldArrayType f.formControl), - { updateOn: field.modelOptions.updateOn }, - )); - } - add(i?: number, initialModel?: any) { i = isNullOrUndefined(i) ? this.field.fieldGroup.length : i; if (!this.model) {