Consuming field "requiredness" in field level (RHF) #10113
Unanswered
alejandrocortes3112
asked this question in
Q&A
Replies: 1 comment 3 replies
-
You can use Working demo: https://codesandbox.io/s/bold-fire-f9wzz0?file=/src/App.tsx |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Libraries
-react 18.2.0
-MUI 5.11.3
-react-hook-form 7.43.5
-yup 1.0.2
Goal
I would like to add an asterisk to the label of fields that are required in yup.
Problem
On the level of my "InputText" I would like to know if the field is required, and in that case append an "*" to the label.
Is there a way to consume the yup schema in useController or useFormContext before the validation executes?
I prefer to avoid passing a duplicate "required" prop or a custom context since I plan to keep input components simple and reusable.
Please see link to my demo code sandbox:
https://codesandbox.io/s/red-fast-oz7qor?file=/src/components/CustomForm/CustomForm.jsx
Thank you in advance
Beta Was this translation helpful? Give feedback.
All reactions