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 = (
|
||||
formData: any,
|
||||
propertyKey: string,
|
||||
propertyMetadata: any,
|
||||
minimumDateCheck: string,
|
||||
formattedDateString: string,
|
||||
errors: any
|
||||
errors: any,
|
||||
jsonSchema: any
|
||||
) => {
|
||||
const fieldIdentifierToCompareWith = propertyMetadata.minimumDate.replace(
|
||||
const fieldIdentifierToCompareWith = minimumDateCheck.replace(
|
||||
/^field:/,
|
||||
''
|
||||
);
|
||||
|
@ -224,8 +225,16 @@ export default function TaskShow() {
|
|||
if (dateToCompareWith) {
|
||||
const dateStringToCompareWith = formatDateString(dateToCompareWith);
|
||||
if (dateStringToCompareWith > formattedDateString) {
|
||||
let fieldToCompareWithTitle = fieldIdentifierToCompareWith;
|
||||
if (
|
||||
fieldIdentifierToCompareWith in jsonSchema.properties &&
|
||||
jsonSchema.properties[fieldIdentifierToCompareWith].title
|
||||
) {
|
||||
fieldToCompareWithTitle =
|
||||
jsonSchema.properties[fieldIdentifierToCompareWith].title;
|
||||
}
|
||||
errors[propertyKey].addError(
|
||||
`must be equal to or greater than '${fieldIdentifierToCompareWith}'`
|
||||
`must be equal to or greater than '${fieldToCompareWithTitle}'`
|
||||
);
|
||||
}
|
||||
} else {
|
||||
|
@ -244,25 +253,30 @@ export default function TaskShow() {
|
|||
formData: any,
|
||||
propertyKey: string,
|
||||
propertyMetadata: any,
|
||||
errors: any
|
||||
errors: any,
|
||||
jsonSchema: any
|
||||
) => {
|
||||
const dateString = formData[propertyKey];
|
||||
if (dateString) {
|
||||
const formattedDateString = formatDateString(dateString);
|
||||
if (propertyMetadata.minimumDate === 'today') {
|
||||
const minimumDateChecks = propertyMetadata.minimumDate.split(',');
|
||||
minimumDateChecks.forEach((mdc: string) => {
|
||||
if (mdc === 'today') {
|
||||
const dateTodayString = formatDateString();
|
||||
if (dateTodayString > formattedDateString) {
|
||||
errors[propertyKey].addError('must be today or after');
|
||||
}
|
||||
} else if (propertyMetadata.minimumDate.startsWith('field:')) {
|
||||
} else if (mdc.startsWith('field:')) {
|
||||
checkFieldComparisons(
|
||||
formData,
|
||||
propertyKey,
|
||||
propertyMetadata,
|
||||
mdc,
|
||||
formattedDateString,
|
||||
errors
|
||||
errors,
|
||||
jsonSchema
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -281,7 +295,13 @@ export default function TaskShow() {
|
|||
Object.keys(jsonSchemaToUse.properties).forEach((propertyKey: string) => {
|
||||
const propertyMetadata = jsonSchemaToUse.properties[propertyKey];
|
||||
if ('minimumDate' in propertyMetadata) {
|
||||
checkMinimumDate(formData, propertyKey, propertyMetadata, errors);
|
||||
checkMinimumDate(
|
||||
formData,
|
||||
propertyKey,
|
||||
propertyMetadata,
|
||||
errors,
|
||||
jsonSchemaToUse
|
||||
);
|
||||
}
|
||||
|
||||
// recurse through all nested properties as well
|
||||
|
|
Loading…
Reference in New Issue