From 5ba5727eece2c252a52f21222309a59b5fffeb55 Mon Sep 17 00:00:00 2001 From: jasquat <2487833+jasquat@users.noreply.github.com> Date: Mon, 22 Apr 2024 17:31:50 +0000 Subject: [PATCH] do not force min and max to be set in numeric range fields w/ burnettk (#1430) Co-authored-by: jasquat Co-authored-by: Kevin Burnett <18027+burnettk@users.noreply.github.com> --- .../NumericRangeField/NumericRangeField.tsx | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/spiffworkflow-frontend/src/rjsf/custom_widgets/NumericRangeField/NumericRangeField.tsx b/spiffworkflow-frontend/src/rjsf/custom_widgets/NumericRangeField/NumericRangeField.tsx index db0fdadc..b9908152 100644 --- a/spiffworkflow-frontend/src/rjsf/custom_widgets/NumericRangeField/NumericRangeField.tsx +++ b/spiffworkflow-frontend/src/rjsf/custom_widgets/NumericRangeField/NumericRangeField.tsx @@ -9,7 +9,7 @@ import { TextInput } from '@carbon/react'; import { getCommonAttributes } from '../../helpers'; // Example jsonSchema - NOTE: the "min" and "max" properties are special names and must be used: -// compensation":{ +// "compensation":{ // "title": "Compensation (yearly), USD", // "type": "object", // "minimum": 0, @@ -26,7 +26,7 @@ import { getCommonAttributes } from '../../helpers'; // // Example uiSchema: // "compensation": { -// "ui:field": "numeric-range", +// "ui:field": "numeric-range" // } // eslint-disable-next-line sonarjs/cognitive-complexity @@ -86,9 +86,6 @@ export default function NumericRangeField({ return Number(numberString.replace(/,/g, '')); }; - if (schema.minimum === undefined || schema.maximum === undefined) { - throw new Error('minimum and maximum not defined'); - } const minNumber = schema.minimum; const maxNumber = schema.maximum; const min = formData?.min; @@ -119,11 +116,22 @@ export default function NumericRangeField({ } }; + let minHelperText = ''; + if (minNumber !== undefined) { + minHelperText = `Min: ${formatNumberString(minNumber?.toString() || '')}`; + } + let maxHelperText = ''; + if (maxNumber !== undefined) { + maxHelperText = `Max: ${formatNumberString(maxNumber?.toString() || '')}`; + } + return (
- {required ? `${commonAttributes.label} *` : commonAttributes.label} + {required + ? commonAttributes.labelWithRequiredIndicator + : commonAttributes.label}
{description && (
@@ -150,7 +158,7 @@ export default function NumericRangeField({ setMinValue(event.target.value); }} invalid={commonAttributes.invalid} - helperText={`Min: ${formatNumberString(minNumber?.toString() || '')}`} + helperText={minHelperText} autofocus={autofocus} />
{commonAttributes.errorMessageForField && (