rjsf-team / react-jsonschema-form

A React component for building Web forms from JSON Schema.
https://rjsf-team.github.io/react-jsonschema-form/
Apache License 2.0
13.88k stars 2.17k forks source link

Custom Error Message for FormData required Fields #4198

Closed SwapnilWankhedeMerit98 closed 15 hours ago

SwapnilWankhedeMerit98 commented 1 month ago

Prerequisites

What theme are you using?

core

What is your question?

Hi,

I am using RJSF for my project and I wanted custom error message for required field validation in formdata. I have tried using transformErrors but didn't work. Also I have made changes in UI schema for required properties but failed. PLease if anyone can suggest a way out would be very helpful. if possible please give a code snippet for the same.

Thanks.

heath-freenome commented 1 month ago

@SwapnilWankhedeMerit98 transformErrors() should have worked. Do you have a codesandbox.io with an example of what you tried to get working? And what do you mean by changes in UI schema for required properties.

SwapnilWankhedeMerit98 commented 1 month ago
Capture3

I want this as custom message. Somewhere I have read to add a UIschema property for the required fields where it will take that message to be displayed. RIght now I can't share the code. WIll share the dummy example of it soon. Meanwhile if you have any solution please do suggest.

heath-freenome commented 1 month ago

FYI, what you are showing us is the standard HTML5 validation behavior that is outside of the control of RJSF. You may want to turn it off using the noHtml5Validate flag on the Form

heath-freenome commented 3 days ago

@SwapnilWankhedeMerit98 Did that flag help?

SwapnilWankhedeMerit98 commented 15 hours ago

@heath-freenome Hey, Thank you for your suggestion. Turning off that flag, don't show those messages, but editing them and customising them is not possible so I have found a workaround. I have removed the required filled in json and displaying the error message manually by checking if field value is empty or not.