diff --git a/src/app/input-form.tsx b/src/app/input-form.tsx index ef2729e..bed9b76 100644 --- a/src/app/input-form.tsx +++ b/src/app/input-form.tsx @@ -10,7 +10,6 @@ import { import styles from "./input-form.module.css"; import "./input-form.css"; import {State} from "@/app/state/state.ts"; -import ValidatingInputBigIntField from "@/app/validating-input-bigint-field.tsx"; export default function InputForm({state, dispatch}: { state: State, @@ -18,7 +17,7 @@ export default function InputForm({state, dispatch}: { }) { const [width, setWidth] = useState(10); const [height, setHeight] = useState(10); - const [id, setId] = useState(); + const [id, setId] = useState(); const [algorithm, setAlgorithm] = useState('wilson'); const handleSubmit = (e: FormEvent) => { @@ -55,14 +54,15 @@ export default function InputForm({state, dispatch}: { value: numberValue }; }; - const validateIdInput: ValidatorFunction = value => { + const validateIdInput: ValidatorFunction = value => { if ("" === value) { return { valid: true }; } - const numberValue = BigInt(value); - if (numberValue.toString() !== value.trim()) { + const numberValue = Number(value); + // FIXME doesn't handle strings with characters correctly (e.g. "asdf" yields an empty value, due to "type=number"). + if (isNaN(numberValue) || Math.floor(numberValue) !== numberValue) { return { valid: false, message: "Must be empty or an integer" @@ -96,7 +96,7 @@ export default function InputForm({state, dispatch}: { disabled={state.loading} onChange={setHeight} /> - { - return {valid: true, value: BigInt(value)}; - }, - disabled = false, - onChange = () => { - } - }: - { - id: string; - label: string; - value?: bigint; - constraints?: { min?: bigint; max?: bigint; }; - validatorFn: ValidatorFunction; - disabled: boolean; - onChange: (v: bigint) => void; - }) { - const [error, setError] = useState(); - - const handleValueChange: ChangeEventHandler = (e) => { - const value = e.target.value; - const validation = validatorFn(value); - if (!validation.valid) { - setError(validation.message); - } else { - setError(undefined); - } - if (validation.value !== undefined) { - onChange(validation.value); - } - }; - return ( - <> - - - {error} - - ); -} - -export interface Validation { - valid: boolean; - message?: string; - value?: T; -} - -export type ValidatorFunction = (v: I) => Validation; diff --git a/tsconfig.json b/tsconfig.json index b953079..ef36eec 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "ES2020", + "target": "ES2017", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "allowImportingTsExtensions": true,