Skip to content
Discussion options

You must be logged in to vote

Controller doesn't pack the valueAs functionality by design.

In the Controller types (omitted most of unrelated types for simplicity):

type UseControllerProps<...> = {
    ...
    rules?: Omit<RegisterOptions<TFieldValues, TName>, 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'>;
    ....
};

You can simply parse your input's value before passing it to the Controller's onChange handler

<Controller
-    rules={{ valueAsNumber: true }}
      render={({ field }) => (
          <input
-             onChange={field.onChange}
+             onChange={(event) => field.onChange(+event.target.value)}
              type="number"
          />
  )}
/>

Replies: 5 comments 17 replies

Comment options

You must be logged in to vote
14 replies
@bluebill1049
Comment options

@AmitNeuhaus
Comment options

@takanuva15
Comment options

@gabriellemos
Comment options

@sacru2red
Comment options

Answer selected by AdiHefferLusha
Comment options

You must be logged in to vote
2 replies
@bluebill1049
Comment options

@cfaester
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

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

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet