Skip to content
This repository has been archived by the owner on Aug 25, 2020. It is now read-only.

Commit

Permalink
fix: fixed two way binding for fields
Browse files Browse the repository at this point in the history
  • Loading branch information
artemnih committed Feb 20, 2019
1 parent f4ced35 commit 77923c2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 81 deletions.
2 changes: 1 addition & 1 deletion dist/ngx-forms.js

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ReactiveFormsModule, FormsModule } from '@angular/forms';
import { DynamicFormDirective } from './dynamic-form/dynamic-form.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FIELD_DICT_TOKEN, LAYOUTS_TOKEN, FormsExtensions } from '../types';
import { FormFieldsModule, defaultInputs } from './fields/fields.module';
import { Fields, FieldComponents } from './fields';
import { FormLayoutsModule, defaultLayouts } from './layouts/layouts.module';
import { DynamicFieldModule } from './dynamic-field/dynamic-field.module';

Expand All @@ -15,19 +15,22 @@ import { DynamicFieldModule } from './dynamic-field/dynamic-field.module';
ReactiveFormsModule,
FormsModule,
FormLayoutsModule,
FormFieldsModule,
DynamicFieldModule
],
declarations: [
DynamicFormDirective
DynamicFormDirective,
FieldComponents
],
entryComponents: [
FieldComponents
],
exports: [
DynamicFormDirective
DynamicFormDirective,
],
providers: [
{
provide: FIELD_DICT_TOKEN,
useValue: defaultInputs
useValue: Fields
},
{
provide: LAYOUTS_TOKEN,
Expand All @@ -40,15 +43,15 @@ import { DynamicFieldModule } from './dynamic-field/dynamic-field.module';
})
export class NgxFormModule {
public static forRoot({ fieldDictionary, layoutDictionary }: FormsExtensions): ModuleWithProviders {
if (fieldDictionary) { Object.keys(fieldDictionary).forEach(key => defaultInputs[key] = fieldDictionary[key]); }
if (fieldDictionary) { Object.keys(fieldDictionary).forEach(key => Fields[key] = fieldDictionary[key]); }
if (layoutDictionary) { Object.keys(layoutDictionary).forEach(key => defaultLayouts[key] = layoutDictionary[key]); }

return {
ngModule: NgxFormModule,
providers: [
{
provide: FIELD_DICT_TOKEN,
useValue: defaultInputs
useValue: Fields
},
{
provide: LAYOUTS_TOKEN,
Expand Down
73 changes: 0 additions & 73 deletions src/app/fields/fields.module.ts

This file was deleted.

34 changes: 34 additions & 0 deletions src/app/fields/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FormInputComponent } from './form-input/form-input.component';
import { FormSelectComponent } from './form-select/form-select.component';
import { FormTextEditorComponent } from './form-text-editor/form-text-editor.component';
import { FormCheckboxComponent } from './form-checkbox/form-checkbox.component';
import { FormRadioComponent } from './form-radio/form-radio.component';
import { FormTextareaComponent } from './form-textarea/form-textarea.component';
import { FormInputHiddenComponent } from './form-hidden/form-hidden.component';
import { FormLabelComponent } from './form-label/form-label.component';
import { FormDateComponent } from './form-date/form-date.component';
import { FieldDictionary } from '../../types';

export const Fields: FieldDictionary = {
text: FormInputComponent,
select: FormSelectComponent,
editor: FormTextEditorComponent,
textarea: FormTextareaComponent,
hidden: FormInputHiddenComponent,
radio: FormRadioComponent,
checkbox: FormCheckboxComponent,
label: FormLabelComponent,
date: FormDateComponent
};

export const FieldComponents = [
FormInputComponent,
FormSelectComponent,
FormTextEditorComponent,
FormTextareaComponent,
FormInputHiddenComponent,
FormRadioComponent,
FormCheckboxComponent,
FormLabelComponent,
FormDateComponent,
];

0 comments on commit 77923c2

Please sign in to comment.