diff --git a/spiffworkflow-frontend/package-lock.json b/spiffworkflow-frontend/package-lock.json index 8466f7a8..8f1b71d6 100644 --- a/spiffworkflow-frontend/package-lock.json +++ b/spiffworkflow-frontend/package-lock.json @@ -46,6 +46,7 @@ "dmn-js": "^12.2.0", "dmn-js-properties-panel": "^1.1", "dmn-js-shared": "^12.1.1", + "jsonpath-plus": "^7.2.0", "jwt-decode": "^3.1.2", "keycloak-js": "^18.0.1", "prop-types": "^15.8.1", @@ -19192,6 +19193,14 @@ "graceful-fs": "^4.1.6" } }, + "node_modules/jsonpath-plus": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-7.2.0.tgz", + "integrity": "sha512-zBfiUPM5nD0YZSBT/o/fbCUlCcepMIdP0CJZxM1+KgA4f2T206f6VAg9e7mX35+KlMaIc5qXW34f3BnwJ3w+RA==", + "engines": { + "node": ">=12.0.0" + } + }, "node_modules/jsonpointer": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-5.0.1.tgz", @@ -45646,6 +45655,11 @@ "universalify": "^2.0.0" } }, + "jsonpath-plus": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/jsonpath-plus/-/jsonpath-plus-7.2.0.tgz", + "integrity": "sha512-zBfiUPM5nD0YZSBT/o/fbCUlCcepMIdP0CJZxM1+KgA4f2T206f6VAg9e7mX35+KlMaIc5qXW34f3BnwJ3w+RA==" + }, "jsonpointer": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/jsonpointer/-/jsonpointer-5.0.1.tgz", diff --git a/spiffworkflow-frontend/package.json b/spiffworkflow-frontend/package.json index 515d191a..23ec3ca2 100644 --- a/spiffworkflow-frontend/package.json +++ b/spiffworkflow-frontend/package.json @@ -41,6 +41,7 @@ "dmn-js": "^12.2.0", "dmn-js-properties-panel": "^1.1", "dmn-js-shared": "^12.1.1", + "jsonpath-plus": "^7.2.0", "jwt-decode": "^3.1.2", "keycloak-js": "^18.0.1", "prop-types": "^15.8.1", diff --git a/spiffworkflow-frontend/src/routes/TaskShow.tsx b/spiffworkflow-frontend/src/routes/TaskShow.tsx index 51bf42e7..238583b1 100644 --- a/spiffworkflow-frontend/src/routes/TaskShow.tsx +++ b/spiffworkflow-frontend/src/routes/TaskShow.tsx @@ -184,12 +184,40 @@ export default function TaskShow() { ); } - function customValidate(formData: any, errors: any) { - if (formData.pass1 !== formData.pass2) { - errors.pass2.addError("Passwords don't match"); + const getFieldsWithDateValidations = (formData: any, errors: any) => { + if ('properties' in jsonSchema) { + Object.keys(jsonSchema.properties).forEach((propertyKey: string) => { + const propertyMetadata = jsonSchema.properties[propertyKey]; + if ('minimum' in propertyMetadata) { + if (propertyMetadata.minimum === 'today') { + const dateToday = new Date(); + const dateValue = formData[propertyKey]; + if (dateValue) { + const dateValueObject = new Date(dateValue); + const dateValueString = dateValueObject + .toISOString() + .split('T')[0]; + const dateTodayString = dateToday.toISOString().split('T')[0]; + if (dateTodayString > dateValueString) { + errors[propertyKey].addError('must be today or after'); + } + } + } + } + }); } return errors; - } + }; + + const customValidate = (formData: any, errors: any) => { + console.log('formData', formData); + console.log('errors', errors); + return getFieldsWithDateValidations(formData, errors); + // if (formData.pass1 !== formData.pass2) { + // errors.pass2.addError("Passwords don't match"); + // } + // return errors; + }; return (