transform number to string (react hook form) #827
Answered
by
fabian-hiller
megacherry
asked this question in
Q&A
-
hi @ all, i have an input "weight" and react hook form. weight can be between 1 and 1000. but with react hook form and controlled inputs the inputs are always string. so how can i transform the input (string) to number and validate it correctly? best regards, |
Beta Was this translation helpful? Give feedback.
Answered by
fabian-hiller
Sep 13, 2024
Replies: 1 comment 1 reply
-
Here is an example: import * as v from 'valibot';
const Schema = v.object({
weight: v.pipe(
v.string(),
v.transform(parseInt),
v.minValue(1),
v.maxValue(1000),
),
}); And to make sure the output of import * as v from 'valibot';
const Schema = v.object({
weight: v.pipe(
v.string(),
v.transform(parseInt),
v.number(),
v.minValue(1),
v.maxValue(1000),
),
});
`` |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
megacherry
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is an example:
And to make sure the output of
transform
is notNaN
you can addnumber
after: