From 47414224689eab95c16d456c66ad556a6269959b Mon Sep 17 00:00:00 2001 From: Umanskiy Aleksey Date: Mon, 21 Oct 2024 17:35:18 +0300 Subject: [PATCH] fix(datepicker): fixed infinite cycle behavior --- src/datepicker/bs-datepicker-input.directive.ts | 5 ++--- src/datepicker/bs-datepicker.component.ts | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/datepicker/bs-datepicker-input.directive.ts b/src/datepicker/bs-datepicker-input.directive.ts index 9186cccade..7ed80f19ad 100644 --- a/src/datepicker/bs-datepicker-input.directive.ts +++ b/src/datepicker/bs-datepicker-input.directive.ts @@ -158,13 +158,13 @@ export class BsDatepickerInputDirective implements ControlValueAccessor, Validat if (this._picker && this._picker.minDate && isBefore(_value, this._picker.minDate, 'date')) { this.writeValue(this._picker.minDate); - return { bsDate: { minDate: this._picker.minDate } }; + return this._picker.ignoreMinMaxErrors ? null : { bsDate: { minDate: this._picker.minDate } }; } if (this._picker && this._picker.maxDate && isAfter(_value, this._picker.maxDate, 'date')) { this.writeValue(this._picker.maxDate); - return { bsDate: { maxDate: this._picker.maxDate } }; + return this._picker.ignoreMinMaxErrors ? null : { bsDate: { maxDate: this._picker.maxDate } }; } } @@ -194,7 +194,6 @@ export class BsDatepickerInputDirective implements ControlValueAccessor, Validat } this._picker.bsValue = this._value; - this._onChange(this._value); } setDisabledState(isDisabled: boolean): void { diff --git a/src/datepicker/bs-datepicker.component.ts b/src/datepicker/bs-datepicker.component.ts index e17cc59516..4c521972f8 100644 --- a/src/datepicker/bs-datepicker.component.ts +++ b/src/datepicker/bs-datepicker.component.ts @@ -72,6 +72,10 @@ export class BsDatepickerDirective implements OnInit, OnDestroy, OnChanges, Afte * Maximum date which is available for selection */ @Input() maxDate?: Date; + /** + * Ignore validation errors when you reset to minDate or maxDate + */ + @Input() ignoreMinMaxErrors?: boolean; /** * Minimum view mode : day, month, or year */