final-form / react-final-form

🏁 High performance subscription-based form state management for React
https://final-form.org/react
MIT License
7.39k stars 481 forks source link

Bug: i18next language change doesn't update validation messages #609

Open 3dos opened 5 years ago

3dos commented 5 years ago

Bug report

Current behavior

Changing language doesn't triggers a language change in already present validation errors. CodeSandbox example: https://codesandbox.io/s/final-form-i18next-fgl1o

To actually reproduce the bug, click on the field without entering a value to make the validation error appear, then switch language with the top button.

Expected behavior

Rerender or provide a way to force rerendering the field when language changes.

istee commented 5 years ago

You could return a function as the error from validate and get the actual string value when rendering the error: https://codesandbox.io/s/final-form-i18next-gcedw

avocadowastaken commented 5 years ago

@3dos I think you should keep only error code in the final form state, and render error message in view https://codesandbox.io/s/final-form-i18next-brb1f

PaulTime commented 5 years ago

@3dos , you can try use

<Field key={i18n.language} .../>

or do as @istee suggested, and wrap RFF Field component with your component like that

import { Field as ReactField } from 'react-final-form';

const Field = ({ t, ...other }) => <ReactField t={t} {...other} />;

export default withTranslations()(Field);

so you don't need to pass every time that dependency