Skip to content

transform number to string (react hook form) #827

Answered by fabian-hiller
megacherry asked this question in Q&A
Discussion options

You must be logged in to vote

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 transform is not NaN you can add number after:

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),
  ),
});
``

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@megacherry
Comment options

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