diff --git a/projects/datetime-picker/src/lib/datetime-input.ts b/projects/datetime-picker/src/lib/datetime-input.ts index 59ca3eb4..1b1eb5e4 100644 --- a/projects/datetime-picker/src/lib/datetime-input.ts +++ b/projects/datetime-picker/src/lib/datetime-input.ts @@ -121,6 +121,9 @@ export class NgxMatDatetimeInput implements ControlValueAccessor, OnDestroy, } private _value: D | null; + @Input() + emitSelectedValueOnCancel = false; + /** The minimum valid date. */ @Input() get min(): D | null { return this._min; } @@ -344,7 +347,7 @@ export class NgxMatDatetimeInput implements ControlValueAccessor, OnDestroy, _onFocus() { // Close datetime picker if opened if (this._datepicker && this._datepicker.opened) { - this._datepicker.cancel(); + this._datepicker.cancel(this.emitSelectedValueOnCancel); } } diff --git a/projects/datetime-picker/src/lib/datetime-picker.component.ts b/projects/datetime-picker/src/lib/datetime-picker.component.ts index ef6055e0..4c1ec188 100644 --- a/projects/datetime-picker/src/lib/datetime-picker.component.ts +++ b/projects/datetime-picker/src/lib/datetime-picker.component.ts @@ -377,9 +377,13 @@ export class NgxMatDatetimePicker implements OnDestroy, CanColor { } /** Cancel and close */ - public cancel(): void { - this._selected = this._rawValue; - this.close(); + public cancel(emitSelectedValueOnCancel: boolean): void { + if (emitSelectedValueOnCancel) { + this.ok(); + } else { + this._selected = this._rawValue; + this.close(); + } } /**