Skip to content

Commit

Permalink
Merge pull request #55 from bcgov/dev
Browse files Browse the repository at this point in the history
Release to prod
  • Loading branch information
timwekkenbc authored Dec 10, 2024
2 parents 4d04b2c + 32d84e1 commit 3a9ff6d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions app/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,19 @@ export const getFieldValidation = (validationCriteria: string, validationType: s
case "[num]": // Number within range (inclusive)
case "(date)": // Date within range (exclusive)
case "[date]": // Date within range (inclusive)
const range = validationCriteria.replace(/[\[\]\(\)]/g, "").split(",");
if (range.length === 2) {
const [minRaw, maxRaw] = validationCriteria
.replace(/[\[\]\(\)]/g, "")
.split(",")
.map((s) => s.trim());
const parseValue = (value: string) => (value === "today" ? new Date() : value);
const min = parseValue(minRaw);
const max = parseValue(maxRaw);

if (minRaw && maxRaw) {
validationRules["range"] = {
min: dataType === "number-input" ? Number(range[0].trim()) : dayjs(range[0].trim()),
max: dataType === "number-input" ? Number(range[1].trim()) : dayjs(range[1].trim()),
inclusive: validationType.startsWith("["), // true for inclusive ranges
min: dataType === "number-input" ? Number(min) : dayjs(min),
max: dataType === "number-input" ? Number(max) : dayjs(max),
inclusive: validationType.startsWith("["),
};
}
break;
Expand Down

0 comments on commit 3a9ff6d

Please sign in to comment.