Skip to content

Commit d5a4e39

Browse files
heightpiasadsahi
authored andcommitted
fix formatting date for all dates (#186)
* fix * formatDateToDisplay fixed * removed console.log
1 parent 505e47a commit d5a4e39

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

ClientApp/app/shared/forms/dynamic-form/dynamic-form.component.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,24 @@ export class DynamicFormComponent implements OnInit, OnDestroy {
6464
private formatDateToDisplay(model: any, controls: Array<ControlBase<any>>) {
6565
const dateField = controls.filter(x => x.type === 'calendar');
6666
if (dateField && dateField.length > 0) {
67-
const controlKey = dateField[0].key;
68-
const stringDate = model[controlKey];
69-
const date = new Date(stringDate);
70-
model[controlKey] = { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() };
67+
for (const control of dateField) {
68+
const controlKey = control.key;
69+
const stringDate = model[controlKey];
70+
const date = new Date(stringDate);
71+
model[controlKey] = { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() };
72+
}
7173
}
7274
}
7375

7476
private formatDateToSave(form: FormGroup) {
7577
const dateField = this.sortedControls.filter(x => x.type === 'calendar');
7678
if (dateField && dateField.length > 0) {
77-
const controlKey = dateField[0].key;
78-
const objectDate = this.form.value[controlKey];
79-
const date = new Date(objectDate.year, objectDate.month - 1, objectDate.day);
80-
this.form.value[controlKey] = date;
79+
for (const control of dateField) {
80+
const controlKey = control.key;
81+
const objectDate = this.form.value[controlKey];
82+
const date = new Date(objectDate.year, objectDate.month - 1, objectDate.day);
83+
this.form.value[controlKey] = date;
84+
}
8185
}
8286
}
8387

0 commit comments

Comments
 (0)