Handle setting default values with api response having null values #10240
Unanswered
ramseylove
asked this question in
Q&A
Replies: 1 comment 1 reply
-
@ramseylove One way to do this is to modify the response from api to check weather it has null value if yes then replace it with an empty string or whatever you like to set and then use reset to set values to form. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The api i'm using sends a null value in a field if there is no data for the field. A few fields requires a textArea component that does not like the null value. I get this error:
'value' prop on 'textarea' should not be null. Consider using an empty string to clear the component or 'undefined' for uncontrolled components.
I'm setting the defaultValues to my api response values. I do not want to change the value unless user actually changes the values (keep null if still blank). Right now i only submit "dirtyFields" and if i set to blank string, it will submit those fields with empty strings. Does anyone have an idea how I can handle this case?
I do not really want to change the value if user doesn't input anything because it will overwrite the null value on the server. but I tried doing a setValue on the field if value is null and got another error:
cannot update a component ('ForwardRef(RhfControlledInput)') while rendering a different component ('Controller'). To locate the bad setState() call inside 'Controller',
Beta Was this translation helpful? Give feedback.
All reactions