trouble with native compatibility with ajv-i18n
See original GitHub issuePrerequisites
- [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
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)

Top Related StackOverflow Question
No, it seems to work fine. If you add the following in
playground/samples/localization.jsin that PR:Then all the error messages are showing up properly in Russian.
I believe this is because the localization function is called directly on the errors returned from ajv, before they are transformed to the format that rjsf returns. See https://github.com/mozilla-services/react-jsonschema-form/pull/846/files#diff-6ca5d88062570937214ee7ea244b05c5R161
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.