Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translating messages inside the form validate prop no longer works #8744

Closed
MaxAlex666 opened this issue Mar 18, 2023 · 3 comments · Fixed by #8746
Closed

Translating messages inside the form validate prop no longer works #8744

MaxAlex666 opened this issue Mar 18, 2023 · 3 comments · Fixed by #8746
Labels

Comments

@MaxAlex666
Copy link

MaxAlex666 commented Mar 18, 2023

Messages inside the global form validation function are now displayed without translation:

const validateUserCreation = (values) => {
    const errors = {};
    if (!values.firstName) {
        errors.firstName = 'The firstName is required';
    }
    if (!values.age) {
        // You can return translation keys
        errors.age = 'ra.validation.required';         // The message is displayed without translation!
    } else if (values.age < 18) {
        // Or an object if the translation messages need parameters
        errors.age = {
            message: 'ra.validation.minValue',       // The message is displayed without translation!
            args: { min: 18 }
        };
    }
    return errors
};

export const UserCreate = () => (
    <Create>
        <Form validate={validateUserCreation}>
            <TextInput label="First Name" source="firstName" />
            <TextInput label="Age" source="age" />
        </Form>
    </Create>
);

React-admin version: 4.8.3
Last version that did not exhibit the issue (if applicable): ~4.8.2
React version: 18.2.0
Browser: Chrome 111.0.5563.65

@djhi
Copy link
Collaborator

djhi commented Mar 18, 2023

Please follow the issue template

@fzaninotto
Copy link
Member

I believe this is a regression introduced by #8700

@slax57
Copy link
Contributor

slax57 commented Mar 20, 2023

You are both right @MaxAlex666 and @fzaninotto
I created a story and added unit tests in #8746 so that we don't run into this issue anymore.
Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants