Skip to content

Commit

Permalink
fix(ngx-formly#346): fixed repeatSection model (ngx-formly#347)
Browse files Browse the repository at this point in the history
* fix(ngx-formly#346): fixed repeatSection model

* feat(deps): update packages
  • Loading branch information
aitboudad authored and mohammedzamakhan committed Dec 16, 2016
1 parent 16e1beb commit 8db16e3
Show file tree
Hide file tree
Showing 4 changed files with 331 additions and 150 deletions.
16 changes: 10 additions & 6 deletions demo/repeatedSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { clone } from '../src/core/utils';
<div *ngFor="let control of formControl.controls; let i = index;">
<formly-form
[model]="model[i]"
[fields]="fields"
[fields]="fields[i]"
[options]="newOptions"
[form]="control"
[form]="this.formControl.at(i)"
[ngClass]="field.fieldArray.className">
</formly-form>
<div class="col-md-2">
Expand All @@ -24,30 +24,34 @@ import { clone } from '../src/core/utils';
`,
})
export class RepeatComponent extends FieldType implements OnInit {
fields = [];

get newOptions() {
return clone(this.options);
}

get fields(): FormlyFieldConfig[] {
return this.field.fieldArray.fieldGroup;
}

ngOnInit() {
if (this.model) {
this.model.map(() => {
(<FormArray>this.formControl).push(new FormGroup({}));
this.fields.push(
JSON.parse(JSON.stringify(this.field.fieldArray.fieldGroup)),
);
});
}
}

add() {
this.model.push({});
this.fields.push(
JSON.parse(JSON.stringify(this.field.fieldArray.fieldGroup)),
);
(<FormArray>this.formControl).push(new FormGroup({}));
}

remove(i) {
(<FormArray>this.formControl).removeAt(i);
this.model.splice(i, 1);
this.fields.splice(i, 1);
}
}
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,42 +51,42 @@
"@angular/forms": "^2.2.0"
},
"devDependencies": {
"@angular/common": "^2.2.4",
"@angular/compiler": "^2.2.4",
"@angular/compiler-cli": "^2.2.4",
"@angular/core": "^2.2.4",
"@angular/forms": "^2.2.3",
"@angular/platform-browser": "^2.2.4",
"@angular/platform-browser-dynamic": "^2.2.4",
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/compiler-cli": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@types/jasmine": "^2.5.38",
"@types/node": "^6.0.51",
"@types/node": "^6.0.52",
"angular2-template-loader": "^0.6.0",
"awesome-typescript-loader": "^3.0.0-beta.5",
"awesome-typescript-loader": "^3.0.0-beta.7",
"codecov": "^1.0.1",
"codelyzer": "2.0.0-beta.1",
"commitizen": "^2.8.6",
"codelyzer": "2.0.0-beta.3",
"commitizen": "^2.9.0",
"core-js": "^2.4.1",
"cz-conventional-changelog": "^1.2.0",
"istanbul-instrumenter-loader": "^0.2.0",
"jasmine": "^2.5.2",
"karma": "^1.3.0",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-jasmine": "^1.1.0",
"karma-mocha-reporter": "^2.2.1",
"karma-phantomjs-launcher": "^1.0.2",
"karma-remap-coverage": "^0.1.2",
"karma-remap-coverage": "^0.1.3",
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "1.8.0",
"phantomjs-prebuilt": "^2.1.13",
"phantomjs-prebuilt": "^2.1.14",
"raw-loader": "^0.5.1",
"remap-istanbul": "^0.7.0",
"rxjs": "^5.0.0-rc.4",
"remap-istanbul": "^0.8.0",
"rxjs": "^5.0.1",
"shx": "^0.2.1",
"tslint": "^4.0.2",
"typescript": "^2.0.7",
"tslint": "^4.1.0",
"typescript": "2.0.10",
"uglify-js": "^2.7.5",
"webpack": "^1.13.3",
"webpack": "^1.14.0",
"webpack-dashboard": "^0.2.0",
"webpack-dev-server": "^1.16.2",
"zone.js": "^0.7.2"
Expand Down
4 changes: 2 additions & 2 deletions src/core/components/formly.field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export class FormlyField implements DoCheck, OnInit {
if (this.field.modelOptions && this.field.modelOptions.debounce && this.field.modelOptions.debounce.default) {
debounce = this.field.modelOptions.debounce.default;
}
let fieldComponentRef = this.createFieldComponent();

const fieldComponentRef = this.createFieldComponent();
if (this.field.key) {
let valueChanges = fieldComponentRef.instance.formControl.valueChanges;
if (debounce > 0) {
Expand Down Expand Up @@ -100,7 +100,7 @@ export class FormlyField implements DoCheck, OnInit {
this.field.wrappers = Array.isArray(this.field.wrapper) ? this.field.wrapper : [this.field.wrapper];
}
if (!this.field.wrappers) this.field.wrappers = [];
let wrappers = [...preWrappers, ...this.field.wrappers, ...postWrappers];
const wrappers = [...preWrappers, ...this.field.wrappers, ...postWrappers];
wrappers.map(wrapperName => {
let wrapperRef = this.createComponent(fieldComponent, this.formlyConfig.getWrapper(wrapperName).component);
fieldComponent = wrapperRef.instance.fieldComponent;
Expand Down
Loading

0 comments on commit 8db16e3

Please sign in to comment.