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

Allow defining custom validation error

Open drodil opened this issue 1 year ago • 5 comments

Prerequisites

What theme are you using?

core

Is your feature request related to a problem? Please describe.

Currently, when there is a for example Regex pattern in the parameter and the user inputs non-valid content to the input, an error is shown. The developers should be able to modify this error message for a better user experience.

Originally reported to https://github.com/backstage/backstage/issues/22575

Describe the solution you'd like

Allow adding optional validationError to the schema that is shown either by replacing the default error or as an addition to it.

Describe alternatives you've considered

No response

drodil avatar Feb 03 '24 10:02 drodil

@drodil There is already support for this built into the Form. Take a look at this documentation

heath-freenome avatar Feb 16 '24 20:02 heath-freenome

Hi, thanks for this. Only problem is that it can only be handled in the Form and not in schema. In backstage there's no access to the rjsf form as a template developer so it's not possible (the templates are only yaml files rendered with rjsf).

I was hoping there was some field in schema to override the default error, but couldn't find anything about that in docs. Is this possible?

drodil avatar Feb 16 '24 20:02 drodil

@drodil Sorry, there is no support for this in the JSON Schema spec OR ajv... You will have to figure out how to customize backstage to allow you to specify a transformErrors function on the Form, or live with the errors.

heath-freenome avatar Feb 22 '24 19:02 heath-freenome

Ok, thanks for this @heath-freenome ! I will continue to investigate this on Backstage side

drodil avatar Feb 22 '24 20:02 drodil