mirror of
https://github.com/sartography/spiff-arena.git
synced 2025-01-27 09:45:12 +00:00
check if min and max values are undefined explicitly when attempting to validate to avoid issues with zero w/ burnettk (#1672)
Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
parent
cee36c2d2d
commit
5cc86a8792
@ -67,7 +67,7 @@ export default function CustomForm({
|
|||||||
reactJsonSchemaFormTheme = 'mui';
|
reactJsonSchemaFormTheme = 'mui';
|
||||||
} else {
|
} else {
|
||||||
console.error(
|
console.error(
|
||||||
`Unsupported theme: ${uiSchema['ui:theme']}. Defaulting to mui`
|
`Unsupported theme: ${uiSchema['ui:theme']}. Defaulting to mui`,
|
||||||
);
|
);
|
||||||
reactJsonSchemaFormTheme = 'mui';
|
reactJsonSchemaFormTheme = 'mui';
|
||||||
}
|
}
|
||||||
@ -93,7 +93,7 @@ export default function CustomForm({
|
|||||||
dateCheck: string,
|
dateCheck: string,
|
||||||
formattedDateString: string,
|
formattedDateString: string,
|
||||||
errors: any,
|
errors: any,
|
||||||
jsonSchema: any
|
jsonSchema: any,
|
||||||
) => {
|
) => {
|
||||||
// field format:
|
// field format:
|
||||||
// field:[field_name_to_use]
|
// field:[field_name_to_use]
|
||||||
@ -105,7 +105,7 @@ export default function CustomForm({
|
|||||||
const [_, fieldIdentifierToCompareWith, startOrEnd] = dateCheck.split(':');
|
const [_, fieldIdentifierToCompareWith, startOrEnd] = dateCheck.split(':');
|
||||||
if (!(fieldIdentifierToCompareWith in formDataToCheck)) {
|
if (!(fieldIdentifierToCompareWith in formDataToCheck)) {
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`was supposed to be compared against '${fieldIdentifierToCompareWith}' but it either doesn't have a value or does not exist`
|
`was supposed to be compared against '${fieldIdentifierToCompareWith}' but it either doesn't have a value or does not exist`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -113,7 +113,7 @@ export default function CustomForm({
|
|||||||
const rawDateToCompareWith = formDataToCheck[fieldIdentifierToCompareWith];
|
const rawDateToCompareWith = formDataToCheck[fieldIdentifierToCompareWith];
|
||||||
if (!rawDateToCompareWith) {
|
if (!rawDateToCompareWith) {
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`was supposed to be compared against '${fieldIdentifierToCompareWith}' but that field did not have a value`
|
`was supposed to be compared against '${fieldIdentifierToCompareWith}' but that field did not have a value`,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ export default function CustomForm({
|
|||||||
if (checkType === 'minimum') {
|
if (checkType === 'minimum') {
|
||||||
if (dateStringToCompareWith > formattedDateString) {
|
if (dateStringToCompareWith > formattedDateString) {
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`must be equal to or greater than '${fieldToCompareWithTitle}'`
|
`must be equal to or greater than '${fieldToCompareWithTitle}'`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// best NOT to merge this with nested if statement in case we add more or move code around
|
// best NOT to merge this with nested if statement in case we add more or move code around
|
||||||
@ -155,7 +155,7 @@ export default function CustomForm({
|
|||||||
} else if (checkType === 'maximum') {
|
} else if (checkType === 'maximum') {
|
||||||
if (dateStringToCompareWith < formattedDateString) {
|
if (dateStringToCompareWith < formattedDateString) {
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`must be equal to or less than '${fieldToCompareWithTitle}'`
|
`must be equal to or less than '${fieldToCompareWithTitle}'`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,7 +168,7 @@ export default function CustomForm({
|
|||||||
propertyKey: string,
|
propertyKey: string,
|
||||||
formattedDateString: string,
|
formattedDateString: string,
|
||||||
errors: any,
|
errors: any,
|
||||||
jsonSchema: any
|
jsonSchema: any,
|
||||||
) => {
|
) => {
|
||||||
dateChecks.forEach((mdc: string) => {
|
dateChecks.forEach((mdc: string) => {
|
||||||
if (mdc === 'today') {
|
if (mdc === 'today') {
|
||||||
@ -192,7 +192,7 @@ export default function CustomForm({
|
|||||||
mdc,
|
mdc,
|
||||||
formattedDateString,
|
formattedDateString,
|
||||||
errors,
|
errors,
|
||||||
jsonSchema
|
jsonSchema,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -204,7 +204,7 @@ export default function CustomForm({
|
|||||||
propertyKey: string,
|
propertyKey: string,
|
||||||
propertyMetadata: any,
|
propertyMetadata: any,
|
||||||
errors: any,
|
errors: any,
|
||||||
jsonSchema: any
|
jsonSchema: any,
|
||||||
) => {
|
) => {
|
||||||
// can be either "today" or another field
|
// can be either "today" or another field
|
||||||
let dateString = formDataToCheck[propertyKey];
|
let dateString = formDataToCheck[propertyKey];
|
||||||
@ -227,7 +227,7 @@ export default function CustomForm({
|
|||||||
propertyKey,
|
propertyKey,
|
||||||
formattedDateString,
|
formattedDateString,
|
||||||
errors,
|
errors,
|
||||||
jsonSchema
|
jsonSchema,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -241,7 +241,7 @@ export default function CustomForm({
|
|||||||
propertyKey: string,
|
propertyKey: string,
|
||||||
errors: any,
|
errors: any,
|
||||||
jsonSchema: any,
|
jsonSchema: any,
|
||||||
uiSchemaPassedIn?: any
|
uiSchemaPassedIn?: any,
|
||||||
) => {
|
) => {
|
||||||
// this validation only applies to checkboxes,
|
// this validation only applies to checkboxes,
|
||||||
// other forms of booleans are validated differently
|
// other forms of booleans are validated differently
|
||||||
@ -259,7 +259,7 @@ export default function CustomForm({
|
|||||||
) {
|
) {
|
||||||
// keep this error the same as the default message
|
// keep this error the same as the default message
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`must have required property '${propertyKey}'`
|
`must have required property '${propertyKey}'`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -269,7 +269,7 @@ export default function CustomForm({
|
|||||||
propertyKey: string,
|
propertyKey: string,
|
||||||
errors: any,
|
errors: any,
|
||||||
jsonSchema: any,
|
jsonSchema: any,
|
||||||
_uiSchemaPassedIn?: any
|
_uiSchemaPassedIn?: any,
|
||||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||||
) => {
|
) => {
|
||||||
if (
|
if (
|
||||||
@ -280,7 +280,7 @@ export default function CustomForm({
|
|||||||
) {
|
) {
|
||||||
errors[propertyKey].addError('must have valid Minimum and Maximum');
|
errors[propertyKey].addError('must have valid Minimum and Maximum');
|
||||||
}
|
}
|
||||||
if (formDataToCheck[propertyKey].min) {
|
if (formDataToCheck[propertyKey].min !== undefined) {
|
||||||
if (
|
if (
|
||||||
!formDataToCheck[propertyKey].min.toString().match(matchNumberRegex)
|
!formDataToCheck[propertyKey].min.toString().match(matchNumberRegex)
|
||||||
) {
|
) {
|
||||||
@ -291,7 +291,7 @@ export default function CustomForm({
|
|||||||
jsonSchema.properties[propertyKey].minimum
|
jsonSchema.properties[propertyKey].minimum
|
||||||
) {
|
) {
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`must have min greater than or equal to ${jsonSchema.properties[propertyKey].minimum}`
|
`must have min greater than or equal to ${jsonSchema.properties[propertyKey].minimum}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
@ -299,11 +299,11 @@ export default function CustomForm({
|
|||||||
jsonSchema.properties[propertyKey].maximum
|
jsonSchema.properties[propertyKey].maximum
|
||||||
) {
|
) {
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`must have min less than or equal to ${jsonSchema.properties[propertyKey].maximum}`
|
`must have min less than or equal to ${jsonSchema.properties[propertyKey].maximum}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (formDataToCheck[propertyKey].max) {
|
if (formDataToCheck[propertyKey].max !== undefined) {
|
||||||
if (
|
if (
|
||||||
!formDataToCheck[propertyKey].max.toString().match(matchNumberRegex)
|
!formDataToCheck[propertyKey].max.toString().match(matchNumberRegex)
|
||||||
) {
|
) {
|
||||||
@ -314,7 +314,7 @@ export default function CustomForm({
|
|||||||
jsonSchema.properties[propertyKey].minimum
|
jsonSchema.properties[propertyKey].minimum
|
||||||
) {
|
) {
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`must have max greater than or equal to ${jsonSchema.properties[propertyKey].minimum}`
|
`must have max greater than or equal to ${jsonSchema.properties[propertyKey].minimum}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
@ -322,7 +322,7 @@ export default function CustomForm({
|
|||||||
jsonSchema.properties[propertyKey].maximum
|
jsonSchema.properties[propertyKey].maximum
|
||||||
) {
|
) {
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`must have max less than or equal to ${jsonSchema.properties[propertyKey].maximum}`
|
`must have max less than or equal to ${jsonSchema.properties[propertyKey].maximum}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -336,7 +336,7 @@ export default function CustomForm({
|
|||||||
propertyKey: string,
|
propertyKey: string,
|
||||||
errors: any,
|
errors: any,
|
||||||
jsonSchema: any,
|
jsonSchema: any,
|
||||||
_uiSchemaPassedIn?: any
|
_uiSchemaPassedIn?: any,
|
||||||
) => {
|
) => {
|
||||||
if (
|
if (
|
||||||
jsonSchema.required &&
|
jsonSchema.required &&
|
||||||
@ -345,7 +345,7 @@ export default function CustomForm({
|
|||||||
formDataToCheck[propertyKey] === '')
|
formDataToCheck[propertyKey] === '')
|
||||||
) {
|
) {
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError(
|
||||||
`must have required property '${propertyKey}'`
|
`must have required property '${propertyKey}'`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -354,7 +354,7 @@ export default function CustomForm({
|
|||||||
jsonSchema: any,
|
jsonSchema: any,
|
||||||
formDataToCheck: any,
|
formDataToCheck: any,
|
||||||
errors: any,
|
errors: any,
|
||||||
uiSchemaPassedIn?: any
|
uiSchemaPassedIn?: any,
|
||||||
// eslint-disable-next-line sonarjs/cognitive-complexity
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||||
) => {
|
) => {
|
||||||
// if the jsonSchema has an items attribute then assume the element itself
|
// if the jsonSchema has an items attribute then assume the element itself
|
||||||
@ -384,7 +384,7 @@ export default function CustomForm({
|
|||||||
propertyKey,
|
propertyKey,
|
||||||
propertyMetadata,
|
propertyMetadata,
|
||||||
errors,
|
errors,
|
||||||
jsonSchemaToUse
|
jsonSchemaToUse,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ('maximumDate' in propertyMetadata) {
|
if ('maximumDate' in propertyMetadata) {
|
||||||
@ -394,7 +394,7 @@ export default function CustomForm({
|
|||||||
propertyKey,
|
propertyKey,
|
||||||
propertyMetadata,
|
propertyMetadata,
|
||||||
errors,
|
errors,
|
||||||
jsonSchemaToUse
|
jsonSchemaToUse,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,7 +404,7 @@ export default function CustomForm({
|
|||||||
propertyKey,
|
propertyKey,
|
||||||
errors,
|
errors,
|
||||||
jsonSchemaToUse,
|
jsonSchemaToUse,
|
||||||
currentUiSchema
|
currentUiSchema,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,7 +418,7 @@ export default function CustomForm({
|
|||||||
propertyKey,
|
propertyKey,
|
||||||
errors,
|
errors,
|
||||||
jsonSchemaToUse,
|
jsonSchemaToUse,
|
||||||
currentUiSchema
|
currentUiSchema,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,7 +432,7 @@ export default function CustomForm({
|
|||||||
propertyKey,
|
propertyKey,
|
||||||
errors,
|
errors,
|
||||||
jsonSchemaToUse,
|
jsonSchemaToUse,
|
||||||
currentUiSchema
|
currentUiSchema,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -451,7 +451,7 @@ export default function CustomForm({
|
|||||||
propertyMetadata,
|
propertyMetadata,
|
||||||
item,
|
item,
|
||||||
errorsToSend,
|
errorsToSend,
|
||||||
currentUiSchema
|
currentUiSchema,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user