Skip to content

Commit

Permalink
chore: Enhance date validation logic in DatePickerWidget2 for better …
Browse files Browse the repository at this point in the history
…granularity checks (#37210)
  • Loading branch information
rahulbarwal committed Nov 5, 2024
1 parent 6dc6194 commit 0df0d8f
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions app/client/src/widgets/DatePickerWidget2/widget/derived.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,31 @@ export default {
let dateValid = true;

if (!!props.minDate && !!props.maxDate) {
dateValid = !!selectedDate
? selectedDate.isBetween(minDate, maxDate)
: !props.isRequired;
if (!selectedDate) {
dateValid = !props.isRequired;
} else {
let granularityToCheck = undefined;
let inclusivityMarkers = undefined;

switch (props.timePrecision) {
case "None":
granularityToCheck = "day";
inclusivityMarkers = "[]";
break;
case "second":
case "minute":
case "millisecond":
granularityToCheck = props.timePrecision;
inclusivityMarkers = "[]";
break;
}
dateValid = selectedDate.isBetween(
minDate,
maxDate,
granularityToCheck,
inclusivityMarkers,
);
}
} else if (!!props.minDate) {
dateValid = !!selectedDate
? selectedDate.isAfter(minDate)
Expand Down

0 comments on commit 0df0d8f

Please sign in to comment.