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

"Friendlier" error messages as part of the uiSchema

Open Eric24 opened this issue 8 years ago • 3 comments
trafficstars

Prerequisites

Description

I realize that you can manipulate the error messages with an external function, but that separates the error text from the schema/uiSchema. I'm a bit surprised that it's not already possible to define custom error messages in the uiSchema (or if it's in there, I couldn't find it). As-is, without the translation function, the error messages are not user-friendly (especially for 'patterns'--very few users would be able to make sense of a regex).

Expected behavior

Ideally, the uiSchema would allow a custom/friendly error message to be defined for a given field and error type, so that instead of the user seeing "does not match pattern '(?=[a-zA-Z][0-9])(?=[0-9][a-zA-Z])^[0-9a-zA-Z]{8,}$' ", they would see "Password must have at least 8 letters or numbers".

I didn't find any discussion about this on github. I'd be curious to know if anyone else has approached the error messages this way, or if using the translation function has met everyone's needs.

Eric24 avatar Sep 06 '17 16:09 Eric24

Some further research turned up this attempt, but it doesn't work (the "built-in" error messages are still shown): https://jsfiddle.net/revolunet/5r3swnr4/

This approach is very similar to my original concept, although I'd rather see the custom messages defined in the uiSchema, since json-schema does not specify a 'messages' property.

Eric24 avatar Sep 06 '17 17:09 Eric24

@Eric24 I have reviewed the jsfiddle provided above and it appears to be working for me. What exactly wasn't working for you?

manahga avatar Sep 08 '17 14:09 manahga

@manahga : Weird...now it works just fine. I'm not sure what happened before, but essentially, the custom messages were not showing. In any case, shouldn't the messages really be defined as part of the uiSchema? After all, they have nothing to do with the actual data layer (in fact, in an internationalized application, there would be multiple language/locale-sensitive uiSchema's, but still only one schema).

Eric24 avatar Sep 09 '17 01:09 Eric24