Skip to content

How to return ControlledInput value as number ? #230

Answered by premdasvm
premdasvm asked this question in Q&A
Discussion options

You must be logged in to vote
const schema = z.object({
customerId: z.number({ required_error: "Customer is required." }),
amount: z
	.string()
	.refine(value => /^\d+$/.test(value), { message: "Amount must be a valid number." }),
});

const onSubmit = ({ customerId, amount }: FormType) => {
	console.log({ customerId, amount: Number(amount) });
};

this is how i'm handling it as of now. Let me know if there is a better way for this.

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@yjose
Comment options

@brunojabs
Comment options

@yjose
Comment options

Answer selected by yjose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants