allow specifying multiple minimum date checks for a field w/ burnettk (#305)
* allow specifying multiple minimum date checks for a field w/ burnettk * show title of field to compare minimum date with --------- Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
parent
27447e533c
commit
1506eed204
|
@ -211,11 +211,12 @@ export default function TaskShow() {
|
||||||
const checkFieldComparisons = (
|
const checkFieldComparisons = (
|
||||||
formData: any,
|
formData: any,
|
||||||
propertyKey: string,
|
propertyKey: string,
|
||||||
propertyMetadata: any,
|
minimumDateCheck: string,
|
||||||
formattedDateString: string,
|
formattedDateString: string,
|
||||||
errors: any
|
errors: any,
|
||||||
|
jsonSchema: any
|
||||||
) => {
|
) => {
|
||||||
const fieldIdentifierToCompareWith = propertyMetadata.minimumDate.replace(
|
const fieldIdentifierToCompareWith = minimumDateCheck.replace(
|
||||||
/^field:/,
|
/^field:/,
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
|
@ -224,8 +225,16 @@ export default function TaskShow() {
|
||||||
if (dateToCompareWith) {
|
if (dateToCompareWith) {
|
||||||
const dateStringToCompareWith = formatDateString(dateToCompareWith);
|
const dateStringToCompareWith = formatDateString(dateToCompareWith);
|
||||||
if (dateStringToCompareWith > formattedDateString) {
|
if (dateStringToCompareWith > formattedDateString) {
|
||||||
|
let fieldToCompareWithTitle = fieldIdentifierToCompareWith;
|
||||||
|
if (
|
||||||
|
fieldIdentifierToCompareWith in jsonSchema.properties &&
|
||||||
|
jsonSchema.properties[fieldIdentifierToCompareWith].title
|
||||||
|
) {
|
||||||
|
fieldToCompareWithTitle =
|
||||||
|
jsonSchema.properties[fieldIdentifierToCompareWith].title;
|
||||||
|
}
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`must be equal to or greater than '${fieldIdentifierToCompareWith}'`
|
`must be equal to or greater than '${fieldToCompareWithTitle}'`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -244,25 +253,30 @@ export default function TaskShow() {
|
||||||
formData: any,
|
formData: any,
|
||||||
propertyKey: string,
|
propertyKey: string,
|
||||||
propertyMetadata: any,
|
propertyMetadata: any,
|
||||||
errors: any
|
errors: any,
|
||||||
|
jsonSchema: any
|
||||||
) => {
|
) => {
|
||||||
const dateString = formData[propertyKey];
|
const dateString = formData[propertyKey];
|
||||||
if (dateString) {
|
if (dateString) {
|
||||||
const formattedDateString = formatDateString(dateString);
|
const formattedDateString = formatDateString(dateString);
|
||||||
if (propertyMetadata.minimumDate === 'today') {
|
const minimumDateChecks = propertyMetadata.minimumDate.split(',');
|
||||||
const dateTodayString = formatDateString();
|
minimumDateChecks.forEach((mdc: string) => {
|
||||||
if (dateTodayString > formattedDateString) {
|
if (mdc === 'today') {
|
||||||
errors[propertyKey].addError('must be today or after');
|
const dateTodayString = formatDateString();
|
||||||
|
if (dateTodayString > formattedDateString) {
|
||||||
|
errors[propertyKey].addError('must be today or after');
|
||||||
|
}
|
||||||
|
} else if (mdc.startsWith('field:')) {
|
||||||
|
checkFieldComparisons(
|
||||||
|
formData,
|
||||||
|
propertyKey,
|
||||||
|
mdc,
|
||||||
|
formattedDateString,
|
||||||
|
errors,
|
||||||
|
jsonSchema
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else if (propertyMetadata.minimumDate.startsWith('field:')) {
|
});
|
||||||
checkFieldComparisons(
|
|
||||||
formData,
|
|
||||||
propertyKey,
|
|
||||||
propertyMetadata,
|
|
||||||
formattedDateString,
|
|
||||||
errors
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -281,7 +295,13 @@ export default function TaskShow() {
|
||||||
Object.keys(jsonSchemaToUse.properties).forEach((propertyKey: string) => {
|
Object.keys(jsonSchemaToUse.properties).forEach((propertyKey: string) => {
|
||||||
const propertyMetadata = jsonSchemaToUse.properties[propertyKey];
|
const propertyMetadata = jsonSchemaToUse.properties[propertyKey];
|
||||||
if ('minimumDate' in propertyMetadata) {
|
if ('minimumDate' in propertyMetadata) {
|
||||||
checkMinimumDate(formData, propertyKey, propertyMetadata, errors);
|
checkMinimumDate(
|
||||||
|
formData,
|
||||||
|
propertyKey,
|
||||||
|
propertyMetadata,
|
||||||
|
errors,
|
||||||
|
jsonSchemaToUse
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// recurse through all nested properties as well
|
// recurse through all nested properties as well
|
||||||
|
|
Loading…
Reference in New Issue