Updating date input type to allow empty dates

This commit is contained in:
2023-03-14 15:59:01 +01:00
parent 4be6591e81
commit 86bcb87427
2 changed files with 8 additions and 2 deletions

View File

@@ -17,7 +17,6 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
<input type="hidden" <input type="hidden"
[formControl]="formControl" [formControl]="formControl"
[formlyAttributes]="field" [formlyAttributes]="field"
[class.is-invalid]="showError"
/> />
<div class="input-group" *ngIf="! this.field.props.readonly"> <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> <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)" (ngModelChange)="changeDatetime($event)"
ngbDatepicker ngbDatepicker
#d="ngbDatepicker" #d="ngbDatepicker"
[class.is-invalid]="showError"
/> />
</div> </div>
<div class="input-group" *ngIf="this.field.props.readonly"> <div class="input-group" *ngIf="this.field.props.readonly">
@@ -49,6 +49,9 @@ export class DateTypeComponent extends FieldType<FieldTypeConfig> implements OnI
ngOnInit() { ngOnInit() {
if (this.formControl.value === undefined) { if (this.formControl.value === undefined) {
this.changeDatetime({}); this.changeDatetime({});
} else {
this.datetime = new Date(this.formControl.value);
this.date = this.getDateStruct(this.datetime);
} }
this.formControl.valueChanges.subscribe(value => { this.formControl.valueChanges.subscribe(value => {

View File

@@ -14,7 +14,6 @@ import { FieldType, FieldTypeConfig } from '@ngx-formly/core';
<input type="hidden" <input type="hidden"
[formControl]="formControl" [formControl]="formControl"
[formlyAttributes]="field" [formlyAttributes]="field"
[class.is-invalid]="showError"
/> />
<div class="input-group" *ngIf="! this.field.props.readonly"> <div class="input-group" *ngIf="! this.field.props.readonly">
<button class="btn btn-outline-secondary bi bi-calendar3" (click)="d.toggle()" type="button"></button> <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)" (ngModelChange)="changeDatetime($event)"
ngbDatepicker ngbDatepicker
#d="ngbDatepicker" #d="ngbDatepicker"
[class.is-invalid]="showError"
/> />
<ngb-timepicker <ngb-timepicker
(ngModelChange)="changeDatetime($event)" (ngModelChange)="changeDatetime($event)"
@@ -54,6 +54,9 @@ export class DatetimeTypeComponent extends FieldType<FieldTypeConfig> implements
ngOnInit() { ngOnInit() {
if (this.formControl.value === undefined) { if (this.formControl.value === undefined) {
this.changeDatetime({}); this.changeDatetime({});
} else {
this.datetime = new Date(this.formControl.value);
this.date = this.getDateStruct(this.datetime);
} }
this.formControl.valueChanges.subscribe(value => { this.formControl.valueChanges.subscribe(value => {