Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion projects/datetime-picker/src/lib/datetime-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ export class NgxMatDatetimeInput<D> implements ControlValueAccessor, OnDestroy,
}
private _value: D | null;

@Input()
emitSelectedValueOnCancel = false;

/** The minimum valid date. */
@Input()
get min(): D | null { return this._min; }
Expand Down Expand Up @@ -344,7 +347,7 @@ export class NgxMatDatetimeInput<D> implements ControlValueAccessor, OnDestroy,
_onFocus() {
// Close datetime picker if opened
if (this._datepicker && this._datepicker.opened) {
this._datepicker.cancel();
this._datepicker.cancel(this.emitSelectedValueOnCancel);
}
}

Expand Down
10 changes: 7 additions & 3 deletions projects/datetime-picker/src/lib/datetime-picker.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,13 @@ export class NgxMatDatetimePicker<D> 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();
}
}

/**
Expand Down