Skip to content

Commit

Permalink
fix(core): disable detect local fields inside wrappers
Browse files Browse the repository at this point in the history
fix #3572
  • Loading branch information
aitboudad committed Oct 6, 2023
1 parent c004d03 commit 22b21d8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/core/src/lib/components/formly.field.spec.ts
Expand Up @@ -604,6 +604,7 @@ describe('FormlyField Component', () => {
it('should emit valueChanges on local field changes', () => {
const { field } = renderComponent({
type: FormlyGroupLocalControlType,
wrappers: ['form-field'],
fieldGroup: [{ key: 'title' }],
});

Expand Down
2 changes: 1 addition & 1 deletion src/core/src/lib/components/formly.field.ts
Expand Up @@ -161,6 +161,7 @@ export class FormlyField implements DoCheck, OnInit, OnChanges, AfterContentInit

private triggerHook(name: keyof FormlyHookConfig, changes?: SimpleChanges) {
if (name === 'onInit' || (name === 'onChanges' && changes.field && !changes.field.firstChange)) {
this.valueChangesUnsubscribe();
this.valueChangesUnsubscribe = this.fieldChanges(this.field);
}

Expand Down Expand Up @@ -267,7 +268,6 @@ export class FormlyField implements DoCheck, OnInit, OnChanges, AfterContentInit
}

private fieldChanges(field: FormlyFieldConfigCache | undefined) {
this.valueChangesUnsubscribe();
if (!field) {
return () => {};
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/src/lib/templates/field.type.ts
@@ -1,6 +1,7 @@
import { Input, Directive, QueryList, ViewChildren } from '@angular/core';
import { FormControl, NgControl, FormGroup } from '@angular/forms';
import { FormlyFieldConfig, FormlyFieldConfigCache } from '../models';
import { FieldWrapper } from './field.wrapper';

Check warning on line 4 in src/core/src/lib/templates/field.type.ts

View workflow job for this annotation

GitHub Actions / build

'FieldWrapper' is defined but never used. Allowed unused vars must match /^_/u

export interface FieldTypeConfig<T = FormlyFieldConfig['props']> extends FormlyFieldConfig<T> {
formControl: FormControl;
Expand All @@ -14,7 +15,7 @@ export interface FieldGroupTypeConfig<T = FormlyFieldConfig['props']> extends Fo

@Directive()
export abstract class FieldType<F extends FormlyFieldConfig = FormlyFieldConfig> {
@ViewChildren(NgControl) set controls(controls: QueryList<NgControl>) {
@ViewChildren(NgControl) set _formlyControls(controls: QueryList<NgControl>) {
const f = this.field as FormlyFieldConfigCache;
f._localFields = controls
.map((c) => (c.control as FormlyFieldConfigCache['formControl'])._fields || [])
Expand Down
4 changes: 3 additions & 1 deletion src/core/src/lib/templates/field.wrapper.ts
@@ -1,9 +1,11 @@
import { ViewContainerRef, ViewChild, Directive } from '@angular/core';
import { ViewContainerRef, ViewChild, Directive, QueryList } from '@angular/core';
import { FieldType } from './field.type';
import { FormlyFieldConfig } from '../models';
import { NgControl } from '@angular/forms';

@Directive()
export abstract class FieldWrapper<F extends FormlyFieldConfig = FormlyFieldConfig> extends FieldType<F> {
override set _formlyControls(_: QueryList<NgControl>) {}
@ViewChild('fieldComponent', { read: ViewContainerRef }) fieldComponent!: ViewContainerRef;
@ViewChild('fieldComponent', { read: ViewContainerRef, static: true }) set _staticContent(content: ViewContainerRef) {
this.fieldComponent = content;
Expand Down

0 comments on commit 22b21d8

Please sign in to comment.