-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Prerequisites
- [v] I have read the documentation;
- [v] In the case of a bug report, I understand that providing a SSCCE example is tremendously useful to the maintainers.
- [v] I'm providing a playground codesandbox (https://codesandbox.io/embed/vm3lz56j53?fontsize=14) demonstrating the issue.
Description
Current realization of errors object incomes in transformErrors (https://react-jsonschema-form.readthedocs.io/en/latest/validation/#custom-error-messages) is incompatible with ajv-i18n (https://github.com/epoberezkin/ajv-i18n)
Since the AJV is used internally, it would be nice to ensure compatibility with AJV native i18n gear, especially considering that such compatibility is very simple to provide by expanding the "erorrs" with one property "keyword", the value for which already exists in members of incoming errors array members as "name" property.
See my playground sample (https://codesandbox.io/embed/vm3lz56j53?fontsize=14), where basic erros array normalizing by map for full compilibility with ajv-i18n localization function.
Steps to Reproduce
- Install and import localization (as sample - directly ru) function for ajv-i18n npm package
- declare transformErrors fucntion where try to call localization function on basic (non modified) errors incoming argument
function transformErrors(errors) { localize_ru(errors); return i18n_normalized; }
- You will take error about missing required 'keyword' property in ajv-i18n
- Then modify your transformErrors, where you previously normilize errors object with basic map
function transformErrors(errors) { const i18n_normalized = errors.map(e => ({ ...e, keyword: e.name })); localize_ru(i18n_normalized); return i18n_normalized; }
- errors messages are succsefully localizated with ajv-i18n
Expected behavior
The erros array members (objects) will have 'keyword' property (duplicated 'name' property value)
PS: May be 'name' property will be renamed to 'keyword' with concurrent refactoring thats usages in other project sources
Actual behavior
The erros array members (objects) not have 'keyword' property, and ajv-i18n localization gear crashes called with the current errors array as argumnet
Version
current major - 1.2.1