@3kles/kles-material-dynamicforms 1.1.5 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -300,16 +300,37 @@
300
300
  };
301
301
  KlesDynamicFormComponent.prototype.createControl = function (field) {
302
302
  var _this = this;
303
- if (field.type === 'listField') {
303
+ if (field.type === 'array') {
304
304
  var array_1 = this.fb.array([]);
305
- field.value.forEach(function (data) {
306
- var subGroup = _this.fb.group({});
305
+ if (field.value && Array.isArray(field.value)) {
306
+ if (field.collections && Array.isArray(field.collections)) {
307
+ field.value.forEach(function (val) {
308
+ var group = _this.fb.group({});
309
+ field.collections.forEach(function (subfield) {
310
+ var data = val[subfield.name] || null;
311
+ var control = _this.createControl(__assign(__assign({}, subfield), (data && { value: data })));
312
+ group.addControl(subfield.name, control);
313
+ });
314
+ array_1.push(group);
315
+ });
316
+ }
317
+ }
318
+ else {
319
+ var group_1 = this.fb.group({});
307
320
  field.collections.forEach(function (subfield) {
308
- var control = _this.createControl(subfield);
309
- subGroup.addControl(subfield.name, control);
321
+ var control = _this.createControl(__assign({}, subfield));
322
+ group_1.addControl(subfield.name, control);
310
323
  });
311
- array_1.push(subGroup);
312
- });
324
+ array_1.push(group_1);
325
+ }
326
+ // field.value.forEach((data: any) => {
327
+ // const subGroup = this.fb.group({});
328
+ // field.collections.forEach(subfield => {
329
+ // const control = this.createControl(subfield);
330
+ // subGroup.addControl(subfield.name, control);
331
+ // });
332
+ // array.push(subGroup);
333
+ // });
313
334
  return array_1;
314
335
  }
315
336
  else if (field.type === 'group') {
@@ -1086,6 +1107,31 @@
1086
1107
  // <mat-button-toggle value="underline">Underline</mat-button-toggle>
1087
1108
  // </mat-button-toggle-group>
1088
1109
 
1110
+ var KlesFormArrayComponent = /** @class */ (function (_super) {
1111
+ __extends(KlesFormArrayComponent, _super);
1112
+ function KlesFormArrayComponent() {
1113
+ return _super !== null && _super.apply(this, arguments) || this;
1114
+ }
1115
+ KlesFormArrayComponent.prototype.ngOnInit = function () {
1116
+ // this.subGroup = this.group.controls[this.field.name] as FormGroup;
1117
+ _super.prototype.ngOnInit.call(this);
1118
+ this.formArray = this.group.controls[this.field.name];
1119
+ console.log('on arrive ici');
1120
+ console.log(this.field);
1121
+ console.log(this.formArray);
1122
+ };
1123
+ KlesFormArrayComponent = __decorate([
1124
+ core.Component({
1125
+ selector: 'kles-array',
1126
+ template: "\n <div [formGroup]=\"group\" class=\"group-container\">\n <ng-container [formArrayName]=\"field.name\">\n <div class=\"group-container\" *ngFor=\"let subGroup of formArray.controls let index = index;\" [style.flex-direction]=\"field.direction || 'row'\"\n [ngClass]=\"field.ngClass\" [ngStyle]=\"field.ngStyle\">\n <ng-container *ngFor=\"let subfield of field.collections;\"\n klesDynamicField [field]=\"subfield\" [group]=\"subGroup\" [siblingFields]=\"field.collections\">\n </ng-container>\n </div>\n </ng-container>\n </div>\n",
1127
+ styles: ['mat-form-field {width: calc(100%)}',
1128
+ ':host { display:flex; flex-direction: inherit}',
1129
+ '.group-container {display:flex; flex-direction: inherit}']
1130
+ })
1131
+ ], KlesFormArrayComponent);
1132
+ return KlesFormArrayComponent;
1133
+ }(KlesFieldAbstract));
1134
+
1089
1135
  var componentMapper = {
1090
1136
  label: KlesFormLabelComponent,
1091
1137
  input: KlesFormInputComponent,
@@ -1095,6 +1141,7 @@
1095
1141
  radio: KlesFormRadioComponent,
1096
1142
  checkbox: KlesFormCheckboxComponent,
1097
1143
  listField: KlesFormListFieldComponent,
1144
+ array: KlesFormArrayComponent,
1098
1145
  color: KlesFormColorComponent,
1099
1146
  chip: KlesFormChipComponent,
1100
1147
  group: KlesFormGroupComponent,
@@ -1711,7 +1758,8 @@
1711
1758
  KlesFormLinkComponent,
1712
1759
  KlesFormSlideToggleComponent,
1713
1760
  KlesFormSelectionListComponent,
1714
- KlesFormButtonToogleGroupComponent
1761
+ KlesFormButtonToogleGroupComponent,
1762
+ KlesFormArrayComponent
1715
1763
  ];
1716
1764
  var directives = [KlesDynamicFieldDirective, KlesComponentDirective];
1717
1765
  var pipes = [KlesTransformPipe, ArrayFormatPipe];
@@ -1785,6 +1833,7 @@
1785
1833
  exports.KlesDynamicFieldDirective = KlesDynamicFieldDirective;
1786
1834
  exports.KlesDynamicFormComponent = KlesDynamicFormComponent;
1787
1835
  exports.KlesFieldAbstract = KlesFieldAbstract;
1836
+ exports.KlesFormArrayComponent = KlesFormArrayComponent;
1788
1837
  exports.KlesFormBadgeComponent = KlesFormBadgeComponent;
1789
1838
  exports.KlesFormButtonCheckerComponent = KlesFormButtonCheckerComponent;
1790
1839
  exports.KlesFormButtonComponent = KlesFormButtonComponent;