diff --git a/editor.planx.uk/src/@planx/components/NumberInput/Editor.tsx b/editor.planx.uk/src/@planx/components/NumberInput/Editor.tsx index 8daf569c78..446462fcbc 100644 --- a/editor.planx.uk/src/@planx/components/NumberInput/Editor.tsx +++ b/editor.planx.uk/src/@planx/components/NumberInput/Editor.tsx @@ -92,12 +92,9 @@ export default function NumberInputComponent(props: Props): FCReturn { - formik.setFieldValue( - "onlyWholeNumbers", - !formik.values.onlyWholeNumbers, - ) + formik.setFieldValue("isInteger", !formik.values.isInteger) } /> } diff --git a/editor.planx.uk/src/@planx/components/NumberInput/Public.test.tsx b/editor.planx.uk/src/@planx/components/NumberInput/Public.test.tsx index 0d4bbbfe41..838a96ea03 100644 --- a/editor.planx.uk/src/@planx/components/NumberInput/Public.test.tsx +++ b/editor.planx.uk/src/@planx/components/NumberInput/Public.test.tsx @@ -92,7 +92,7 @@ test("a clear error is shown if decimal value added when onlyWholeNumbers is tog fn="fahrenheit" title="What's the temperature?" handleSubmit={handleSubmit} - onlyWholeNumbers={true} + isInteger={true} />, ); @@ -117,7 +117,7 @@ test("allows only whole numbers to be submitted when toggled on by editor", asyn fn="fahrenheit" title="What's the temperature?" handleSubmit={handleSubmit} - onlyWholeNumbers={true} + isInteger={true} />, ); diff --git a/editor.planx.uk/src/@planx/components/NumberInput/model.ts b/editor.planx.uk/src/@planx/components/NumberInput/model.ts index 6913676743..686d483d4b 100644 --- a/editor.planx.uk/src/@planx/components/NumberInput/model.ts +++ b/editor.planx.uk/src/@planx/components/NumberInput/model.ts @@ -8,7 +8,7 @@ export interface NumberInput extends BaseNodeData { fn?: string; units?: string; allowNegatives?: boolean; - onlyWholeNumbers?: boolean; + isInteger?: boolean; } export type UserData = number; @@ -29,7 +29,7 @@ export const parseNumberInput = ( fn: data?.fn || "", units: data?.units, allowNegatives: data?.allowNegatives || false, - onlyWholeNumbers: data?.onlyWholeNumbers || false, + isInteger: data?.isInteger || false, ...parseBaseNodeData(data), }); @@ -62,7 +62,7 @@ export const numberInputValidationSchema = (input: NumberInput) => if (!value) { return false; } - if (input.onlyWholeNumbers && !Number.isInteger(Number(value))) { + if (input.isInteger && !Number.isInteger(Number(value))) { return false; } return true;