Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 14x 10x 9x 1x 1x 1x 9x 1x 9x 1x | import { GiveInput, InputProps } from "@shared/GiveInputs/GiveInput";
import { useFormContext } from "react-hook-form";
interface CustomProps {
allowAnything?: boolean;
}
const ZipField = (props: InputProps & CustomProps) => {
const { setValue } = useFormContext();
const normalizeInput = (value: string) => {
Iif (!value || props.allowAnything) return value;
const currentValue = value.replace(/[^\d\s-]/g, "");
return currentValue;
};
const handleChange = (value: string) => {
setValue(`${props.name}`, normalizeInput(value), { shouldValidate: true });
};
return (
<GiveInput
{...props}
onChange={(event) => handleChange(event.target.value)}
maxLength={props.allowAnything ? 20 : 10}
InputProps={{
inputMode: props.allowAnything ? "text" : "numeric",
}}
/>
);
};
export default ZipField;
|