minDate maxDate validation for manually inserted date via input
I'm submitting a ...
[X] feature request
Current behavior MinDate and MaxDate only works inside Calendar (dates are disabled) but date can be changed manually to invalid value by editing input directly.
Expected behavior After editing input value, component should be marked as invalid.
Since it's not included in the current releases, is there any update when this is going to be fixed?
Any updates on that?
@cagataycivici any update on the issue?
👍
So was the fix for this rolled back?
any updates on this one?
Any updates on this one? This is really frustrating to try and work around!
I think this issue is caused by onUserInput() in calendar.ts ( release 11.0.0):
onUserInput(event) {
// IE 11 Workaround for input placeholder : https://github.com/primefaces/primeng/issues/2026
if (!this.isKeydown) {
return;
}
this.isKeydown = false;
let val = event.target.value;
try {
let value = this.parseValueFromString(val);
if (this.isValidSelection(value)) {
this.updateModel(value);
this.updateUI();
}
}
catch(err) {
//invalid date
this.updateModel(null);
}
this.filled = val != null && val.length;
this.onInput.emit(event);
}
It happens for a p-calendar control configured with a date range, but without the [readonlyInput]="true" flag:
<p-calendar [(ngModel)]="dateValue" [minDate]="minDateValue" [maxDate]="maxDateValue"></p-calendar>
When the user enters a parsable date outside of the minDate-maxDate range, isValidSelection(value) returns false and the control does not update its model.
It would be more consistent if a manually entered invalid date (outside min-max range) called this.updateModel(null) i.e. treated an out-of-range date the same as an unparsable date.
As it stands now, if you have a valid date (within min-max date) and you manually paste in an invalid date then the model does not update. So the control will display the new value, but keeps its original value and validation state.
However, if you manually type in the same invalid date then the internal value will update to null as you type - because the intermediate contents of the input will be unparsable as a date.
This is not a great user experience, and can lead to difficult to diagnose problems.
For template driven forms (using ngModel) the current work-around in the documentation is to set [readonlyInput]="true":
https://www.primefaces.org/primeng/showcase/#/calendar
If you are using Reactive Forms then another approach is to set validators on your FormControl instance and ignore the minDate and maxDate properties on p-calendar.
But it would be nice if the Calendar control updated its model for manually entered out-of-range dates.
Any updates on this one? This issue is a big trouble for Reactive Forms, not just an enhancement.
Is there any chance for fix? I'm also relying on calendar min/max date ranges but manual input doesn't take it into account.
Hi,
So sorry for the delayed response! Improvements have been made to many components recently, both in terms of performance and enhancement. Therefore, this improvement may have been developed in another issue ticket without realizing it. You can check this in the documentation. If there is no improvement on this, can you reopen the issue so we can include it in our roadmap? Please don't forget to add your feedback as a comment after reopening the issue. These will be taken into account by us and will contribute to the development of this feature. Thanks a lot for your understanding!
Best Regards,