do not invalidate a numeric range field if it is unset and not required (#1478)
Co-authored-by: jasquat <jasquat@users.noreply.github.com>
This commit is contained in:
parent
fa8f46d04b
commit
b9e70d12a6
|
@ -256,6 +256,7 @@ export default function CustomForm({
|
||||||
errors: any,
|
errors: any,
|
||||||
jsonSchema: any,
|
jsonSchema: any,
|
||||||
_uiSchemaPassedIn?: any
|
_uiSchemaPassedIn?: any
|
||||||
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
||||||
) => {
|
) => {
|
||||||
if (
|
if (
|
||||||
jsonSchema.required &&
|
jsonSchema.required &&
|
||||||
|
@ -265,43 +266,51 @@ export default function CustomForm({
|
||||||
) {
|
) {
|
||||||
errors[propertyKey].addError('must have valid Minimum and Maximum');
|
errors[propertyKey].addError('must have valid Minimum and Maximum');
|
||||||
}
|
}
|
||||||
if (
|
if (formDataToCheck[propertyKey].min) {
|
||||||
!formDataToCheck[propertyKey].min?.toString().match(matchNumberRegex) ||
|
if (
|
||||||
!formDataToCheck[propertyKey].max?.toString().match(matchNumberRegex)
|
!formDataToCheck[propertyKey].min.toString().match(matchNumberRegex)
|
||||||
) {
|
) {
|
||||||
errors[propertyKey].addError('must have valid numbers');
|
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 (
|
if (formDataToCheck[propertyKey].max) {
|
||||||
formDataToCheck[propertyKey].min <
|
if (
|
||||||
jsonSchema.properties[propertyKey].minimum
|
!formDataToCheck[propertyKey].max.toString().match(matchNumberRegex)
|
||||||
) {
|
) {
|
||||||
errors[propertyKey].addError(
|
errors[propertyKey].addError('must have valid numbers');
|
||||||
`must have min greater than or equal to ${jsonSchema.properties[propertyKey].minimum}`
|
}
|
||||||
);
|
if (
|
||||||
}
|
formDataToCheck[propertyKey].max <
|
||||||
if (
|
jsonSchema.properties[propertyKey].minimum
|
||||||
formDataToCheck[propertyKey].min >
|
) {
|
||||||
jsonSchema.properties[propertyKey].maximum
|
errors[propertyKey].addError(
|
||||||
) {
|
`must have max greater than or equal to ${jsonSchema.properties[propertyKey].minimum}`
|
||||||
errors[propertyKey].addError(
|
);
|
||||||
`must have min less than or equal to ${jsonSchema.properties[propertyKey].maximum}`
|
}
|
||||||
);
|
if (
|
||||||
}
|
formDataToCheck[propertyKey].max >
|
||||||
if (
|
jsonSchema.properties[propertyKey].maximum
|
||||||
formDataToCheck[propertyKey].max <
|
) {
|
||||||
jsonSchema.properties[propertyKey].minimum
|
errors[propertyKey].addError(
|
||||||
) {
|
`must have max less than or equal to ${jsonSchema.properties[propertyKey].maximum}`
|
||||||
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) {
|
if (formDataToCheck[propertyKey].min > formDataToCheck[propertyKey].max) {
|
||||||
errors[propertyKey].addError(`must have min less than or equal to max`);
|
errors[propertyKey].addError(`must have min less than or equal to max`);
|
||||||
|
|
|
@ -83,6 +83,9 @@ export default function NumericRangeField({
|
||||||
};
|
};
|
||||||
|
|
||||||
const parseNumberString = (numberString: string) => {
|
const parseNumberString = (numberString: string) => {
|
||||||
|
if (!numberString.match(matchNumberRegex)) {
|
||||||
|
return numberString;
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
(numberString === '-' && numberString.length === 1) ||
|
(numberString === '-' && numberString.length === 1) ||
|
||||||
numberString.endsWith('.')
|
numberString.endsWith('.')
|
||||||
|
|
Loading…
Reference in New Issue