added proof of concept to validate date fields in json schema form w/ burnettk
This commit is contained in:
parent
afa0256bc3
commit
ccf64e5bcb
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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 (
|
||||
<Grid fullWidth condensed>
|
||||
|
|
Loading…
Reference in New Issue