Skip to content

Commit

Permalink
fix(core/utils): format date values in the deepCopy of a form
Browse files Browse the repository at this point in the history
  • Loading branch information
sara-gnucoop committed Mar 22, 2023
1 parent d0952ec commit 8cd3566
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
13 changes: 13 additions & 0 deletions projects/core/utils/src/deep-copy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,23 @@
*
*/

import {format} from 'date-fns';

function functionSerializer(_: any, v: any): any {
if (typeof v === 'function') {
return v.toString().replace(/[\r\n]+/g, ' ');
}
if (isNaN(v) && typeof v === 'string') {
try {
const d = new Date(v);
if (d instanceof Date) {
return format(d, 'yyyy-MM-dd');
}
} catch (e) {}
}
if (typeof v === 'object' && v instanceof Date) {
return format(v, 'yyyy-MM-dd');
}
return v;
}

Expand Down
1 change: 0 additions & 1 deletion projects/material/forms/src/date-input-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[attr.aria-label]="instance!|ajfNodeCompleteName"
[min]="instance!.node.minDate|ajfDateValueString"
[max]="instance!.node.maxDate|ajfDateValueString"
(change)="onChange()"
[formControl]="ctrl!"
/>
<mat-datepicker-toggle matIconSuffix [for]="picker"></mat-datepicker-toggle>
Expand Down
28 changes: 11 additions & 17 deletions projects/material/forms/src/date-input-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ import {
ViewChild,
ViewEncapsulation,
} from '@angular/core';

import {MatInput} from '@angular/material/input';

import {AjfWarningAlertService} from './warning-alert-service';

@Component({
Expand All @@ -49,31 +47,27 @@ import {AjfWarningAlertService} from './warning-alert-service';
export class AjfDateInputFieldComponent extends AjfBaseFieldComponent<AjfDateFieldInstance> {
@ViewChild(MatInput, {static: false}) input!: MatInput;

private _minDateStr: string | undefined;
private _maxDateStr: string | undefined;

constructor(
cdr: ChangeDetectorRef,
service: AjfFormRendererService,
@Inject(AJF_WARNING_ALERT_SERVICE) was: AjfWarningAlertService,
private _dvs: AjfDateValueStringPipe,
) {
super(cdr, service, was);
}

onChange(): void {
if (this.input == null) {
// TODO is this function useful??
/*
onChange(event: MatDatepickerInputEvent<Date>): void {
if (event.value == null) {
return;
}
const val = this.input.value || '';
if (val.length > 0) {
if (
(this._minDateStr != null && val < this._minDateStr) ||
(this._maxDateStr != null && val > this._maxDateStr)
) {
this.input.value = '';
}
if (
(this._minDateStr != null && event.value < new Date(this._minDateStr)) ||
(this._maxDateStr != null && event.value > new Date(this._maxDateStr))
) {
this.input.value = '';
}
}
protected override _onInstanceChange(): void {
Expand All @@ -82,5 +76,5 @@ export class AjfDateInputFieldComponent extends AjfBaseFieldComponent<AjfDateFie
}
this._minDateStr = this._dvs.transform(this.instance.node.minDate);
this._maxDateStr = this._dvs.transform(this.instance.node.maxDate);
}
}*/
}

0 comments on commit 8cd3566

Please sign in to comment.