Skip to content

Commit

Permalink
do not invalidate a numeric range field if it is unset and not requir…
Browse files Browse the repository at this point in the history
…ed (#1478)

Co-authored-by: jasquat <[email protected]>
  • Loading branch information
jasquat and jasquat authored May 2, 2024
1 parent fa8f46d commit b9e70d1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 36 deletions.
81 changes: 45 additions & 36 deletions spiffworkflow-frontend/src/components/CustomForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ export default function CustomForm({
errors: any,
jsonSchema: any,
_uiSchemaPassedIn?: any
// eslint-disable-next-line sonarjs/cognitive-complexity
) => {
if (
jsonSchema.required &&
Expand All @@ -265,43 +266,51 @@ export default function CustomForm({
) {
errors[propertyKey].addError('must have valid Minimum and Maximum');
}
if (
!formDataToCheck[propertyKey].min?.toString().match(matchNumberRegex) ||
!formDataToCheck[propertyKey].max?.toString().match(matchNumberRegex)
) {
errors[propertyKey].addError('must have valid numbers');
}
if (
formDataToCheck[propertyKey].min <
jsonSchema.properties[propertyKey].minimum
) {
errors[propertyKey].addError(
`must have min greater than or equal to ${jsonSchema.properties[propertyKey].minimum}`
);
}
if (
formDataToCheck[propertyKey].min >
jsonSchema.properties[propertyKey].maximum
) {
errors[propertyKey].addError(
`must have min less than or equal to ${jsonSchema.properties[propertyKey].maximum}`
);
}
if (
formDataToCheck[propertyKey].max <
jsonSchema.properties[propertyKey].minimum
) {
errors[propertyKey].addError(
`must have max greater than or equal to ${jsonSchema.properties[propertyKey].minimum}`
);
if (formDataToCheck[propertyKey].min) {
if (
!formDataToCheck[propertyKey].min.toString().match(matchNumberRegex)
) {
errors[propertyKey].addError('must have valid numbers');
}
if (
formDataToCheck[propertyKey].min <
jsonSchema.properties[propertyKey].minimum
) {
errors[propertyKey].addError(
`must have min greater than or equal to ${jsonSchema.properties[propertyKey].minimum}`
);
}
if (
formDataToCheck[propertyKey].min >
jsonSchema.properties[propertyKey].maximum
) {
errors[propertyKey].addError(
`must have min less than or equal to ${jsonSchema.properties[propertyKey].maximum}`
);
}
}
if (
formDataToCheck[propertyKey].max >
jsonSchema.properties[propertyKey].maximum
) {
errors[propertyKey].addError(
`must have max less than or equal to ${jsonSchema.properties[propertyKey].maximum}`
);
if (formDataToCheck[propertyKey].max) {
if (
!formDataToCheck[propertyKey].max.toString().match(matchNumberRegex)
) {
errors[propertyKey].addError('must have valid numbers');
}
if (
formDataToCheck[propertyKey].max <
jsonSchema.properties[propertyKey].minimum
) {
errors[propertyKey].addError(
`must have max greater than or equal to ${jsonSchema.properties[propertyKey].minimum}`
);
}
if (
formDataToCheck[propertyKey].max >
jsonSchema.properties[propertyKey].maximum
) {
errors[propertyKey].addError(
`must have max less than or equal to ${jsonSchema.properties[propertyKey].maximum}`
);
}
}
if (formDataToCheck[propertyKey].min > formDataToCheck[propertyKey].max) {
errors[propertyKey].addError(`must have min less than or equal to max`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ export default function NumericRangeField({
};

const parseNumberString = (numberString: string) => {
if (!numberString.match(matchNumberRegex)) {
return numberString;
}
if (
(numberString === '-' && numberString.length === 1) ||
numberString.endsWith('.')
Expand Down

0 comments on commit b9e70d1

Please sign in to comment.