react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

Custom Error Message for FormData required Fields

Open SwapnilWankhedeMerit98 opened this issue 1 year ago • 3 comments

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.

SwapnilWankhedeMerit98 avatar May 23 '24 06:05 SwapnilWankhedeMerit98

@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.

heath-freenome avatar May 24 '24 19:05 heath-freenome

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.

SwapnilWankhedeMerit98 avatar May 29 '24 13:05 SwapnilWankhedeMerit98

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 avatar May 29 '24 16:05 heath-freenome

@SwapnilWankhedeMerit98 Did that flag help?

heath-freenome avatar Jul 05 '24 19:07 heath-freenome

@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.

SwapnilWankhedeMerit98 avatar Jul 08 '24 04:07 SwapnilWankhedeMerit98