Skip to content
This repository was archived by the owner on Aug 25, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/ngx-forms.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/app/dynamic-form/dynamic-form.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ describe('DynamicFormDirective', () => {


it('should call changes()', () => {
expect(dir.changes).toEqual(dir.formGroup.valueChanges);
expect(dir.changes).toEqual(dir.group.valueChanges);
});

it('should call valid()', () => {
expect(dir.valid).toEqual(dir.formGroup.valid);
expect(dir.valid).toEqual(dir.group.valid);
});

it('should call value()', () => {
expect(dir.value).toEqual(dir.formGroup.value);
expect(dir.value).toEqual(dir.group.value);
});

it('should call value()', () => {
expect(dir.rawValue).toEqual(dir.formGroup.getRawValue());
expect(dir.rawValue).toEqual(dir.group.getRawValue());
});

});
Expand Down
14 changes: 7 additions & 7 deletions src/app/dynamic-form/dynamic-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ export class DynamicFormDirective implements OnInit {
@Input() model: any;
@Input() lookups: object;

public formGroup: FormGroup;
get changes() { return this.formGroup.valueChanges; }
get valid() { return this.formGroup.valid; }
get value() { return this.formGroup.value; }
get rawValue() { return this.formGroup.getRawValue(); }
public group: FormGroup;
get changes() { return this.group.valueChanges; }
get valid() { return this.group.valid; }
get value() { return this.group.value; }
get rawValue() { return this.group.getRawValue(); }

constructor(
private componentFactoryResolver: ComponentFactoryResolver,
private container: ViewContainerRef,
@Inject(LAYOUTS_TOKEN) private layouts: LayoutDictionary) {
this.formGroup = new FormGroup({});
this.group = new FormGroup({});
}

public ngOnInit(): void {
Expand All @@ -31,7 +31,7 @@ export class DynamicFormDirective implements OnInit {
const componentReference = this.layouts[this.formConfig.layout];
const componentFactory = this.componentFactoryResolver.resolveComponentFactory<Layout>(componentReference);
const component = this.container.createComponent(componentFactory);
component.instance.formGroup = this.formGroup;
component.instance.group = this.group;
component.instance.formConfig = this.formConfig;
component.instance.model = this.model;
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/layouts/base-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ export class BaseLayout implements Layout {
@Input() formConfig: FormConfig;
@Input() model: any;
@Input() lookups: object;
@Input() formGroup: FormGroup;
@Input() group: FormGroup;
}
2 changes: 1 addition & 1 deletion src/app/layouts/basic/basic-layout.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h2>{{formConfig.title}}</h2>
</label>

<div class="col-md-10">
<div dynamicField [field]="field" [group]="formGroup" [model]="model"></div>
<div dynamicField [field]="field" [group]="group" [model]="model"></div>
</div>

</div>
Expand Down
4 changes: 2 additions & 2 deletions src/app/layouts/basic/basic-layout.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('BasicLayoutComponent Core', () => {
beforeEach(() => {
fixture = TestBed.createComponent(BasicLayoutComponent);
component = fixture.componentInstance;
component.formGroup = new FormGroup({})
component.group = new FormGroup({})
component.formConfig = {
form: [
{ label: 'fields and panels', panels: [{ label: 'fields', fields: [{ type: 'text', name: 'title', required: true }] }] },
Expand All @@ -69,7 +69,7 @@ describe('BasicLayoutComponent Core', () => {
describe('ngOnInit()', () => {

it('should create group', () => {
expect(component.formGroup).toBeDefined();
expect(component.group).toBeDefined();
});

});
Expand Down
9 changes: 5 additions & 4 deletions src/app/layouts/groups/group/group.component.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<div class="row">
<div class="col-md-2">
<form-nav [form]="formGroup"></form-nav>
<form-nav [form]="group"></form-nav>
</div>
<div class="col-md-10" [formGroup]="formGroup">
<div class="col-md-10" [formGroup]="group">
<div *ngFor="let panel of formConfig.form" [navTab]="panel">

<ng-container *ngIf="panel.fields">
<layout-group-panel [panelConfig]="panel" [group]="formGroup" [model]="model" [hidden]="panel.hidden"></layout-group-panel>
<layout-group-panel [panelConfig]="panel" [group]="group" [model]="model" [hidden]="panel.hidden">
</layout-group-panel>
</ng-container>

<ng-container *ngIf="panel.panels">
<layout-group-panel *ngFor="let panelConfig of panel.panels" [panelConfig]="panelConfig" [group]="formGroup"
<layout-group-panel *ngFor="let panelConfig of panel.panels" [panelConfig]="panelConfig" [group]="group"
[model]="model" [hidden]="panel.hidden"></layout-group-panel>
</ng-container>
</div>
Expand Down
4 changes: 2 additions & 2 deletions src/app/layouts/groups/group/group.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ describe('GroupComponent Core', () => {
beforeEach(() => {
fixture = TestBed.createComponent(GroupComponent);
component = fixture.componentInstance;
component.formGroup = new FormGroup({})
component.group = new FormGroup({})
component.formConfig = {
form: [
{ label: 'fields and panels', panels: [{ label: 'fields', fields: [{ type: 'text', name: 'title', required: true }] }] },
Expand All @@ -127,7 +127,7 @@ describe('GroupComponent Core', () => {
describe('ngOnInit()', () => {

it('should create group', () => {
expect(component.formGroup).toBeDefined();
expect(component.group).toBeDefined();
});

describe('Lookup Expansion', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const FIELD_DICT_TOKEN = new InjectionToken<FieldDictionary>('fields');
export const LAYOUTS_TOKEN = new InjectionToken<Layout>('layouts');

export interface Layout {
formGroup: FormGroup;
group: FormGroup;
formConfig: any;
model: any;
}
Expand Down