Updating date input type to allow empty dates

This commit is contained in:
ewandor committed 2023-03-14 15:59:01 +01:00
1 parent 4be6591e81
commit 86bcb87427
2 files changed
+8 -2

No files matched your search

+4 -1
View File
@@ -17,7 +17,6 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
<input type="hidden"
[formControl]="formControl"
[formlyAttributes]="field"
[class.is-invalid]="showError"
/>
<div class="input-group" *ngIf="! this.field.props.readonly">
<button class="btn btn-outline-secondary" (click)="d.toggle()" type="button"><i-bs name="calendar-date-fill"></i-bs></button>
@@ -29,6 +28,7 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
(ngModelChange)="changeDatetime($event)"
ngbDatepicker
#d="ngbDatepicker"
[class.is-invalid]="showError"
/>
</div>
<div class="input-group" *ngIf="this.field.props.readonly">
@@ -49,6 +49,9 @@ export class DateTypeComponent extends FieldType<FieldTypeConfig> implements OnI
ngOnInit() {
if (this.formControl.value === undefined) {
this.changeDatetime({});
} else {
this.datetime = new Date(this.formControl.value);
this.date = this.getDateStruct(this.datetime);
}
this.formControl.valueChanges.subscribe(value => {
@@ -14,7 +14,6 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
<input type="hidden"
[formControl]="formControl"
[formlyAttributes]="field"
[class.is-invalid]="showError"
/>
<div class="input-group" *ngIf="! this.field.props.readonly">
<button class="btn btn-outline-secondary bi bi-calendar3" (click)="d.toggle()" type="button"></button>
@@ -26,6 +25,7 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
(ngModelChange)="changeDatetime($event)"
ngbDatepicker
#d="ngbDatepicker"
[class.is-invalid]="showError"
/>
<ngb-timepicker
(ngModelChange)="changeDatetime($event)"
@@ -54,6 +54,9 @@ export class DatetimeTypeComponent extends FieldType<FieldTypeConfig> implements
ngOnInit() {
if (this.formControl.value === undefined) {
this.changeDatetime({});
} else {
this.datetime = new Date(this.formControl.value);
this.date = this.getDateStruct(this.datetime);
}
this.formControl.valueChanges.subscribe(value => {