Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #13132 : Calendar: onModelChange not called with keepInvalid=true if user enters a well-formatted date but outside allowed range #13133

Merged
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
27 changes: 27 additions & 0 deletions src/app/components/calendar/calendar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,33 @@ describe('Calendar', () => {
expect(onModelTouchedSpy).toHaveBeenCalled();
});

it('should trigger onModelChange when user input a well-formatted but invalid value with keepInvalid=true', () => {

const today = new Date();

calendar.keepInvalid = true;
calendar.dateFormat = 'yy/mm/dd';
calendar.minDate = today;
fixture.detectChanges();

const onModelChangeSpy = spyOn(calendar, 'onModelChange').and.callThrough();

const inputEl = fixture.debugElement.query(By.css('.p-inputtext'));
const focusEvent = new Event('focus');
const blurEvent = new Event('blur');

inputEl.nativeElement.click();
inputEl.nativeElement.dispatchEvent(focusEvent);
fixture.detectChanges();
expect(onModelChangeSpy).not.toHaveBeenCalled();

// simulate user input
inputEl.nativeElement.value = '2000/01/01'; // <-- an invalid value (= before today)
calendar.isKeydown = true;
calendar.onUserInput({ target: inputEl.nativeElement });
expect(onModelChangeSpy).toHaveBeenCalled();
});

it('should change appendto', () => {
calendar.appendTo = 'body';
const date = new Date(2017, 8, 23);
Expand Down
2 changes: 2 additions & 0 deletions src/app/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2566,6 +2566,8 @@ export class Calendar implements OnInit, OnDestroy, ControlValueAccessor {
if (this.isValidSelection(value)) {
this.updateModel(value);
this.updateUI();
} else if (this.keepInvalid) {
this.updateModel(value);
}
} catch (err) {
//invalid date
Expand Down