translate string in asyncValidate function

102 views Asked by At

How I can translate error string using:

import { translate } from 'react-admin';

const CompanyValidate = (values) => {
    return asyncValidate('companies', [
        {
            filters: {
                'code': code,
            },
            errorMessage: {
                'code': 'Error String'
            }
        }
    ]);
};

const CompanyCreate = (props) => (
    <Create
        {...props}
    >
        <SimpleForm
        asyncValidate={CompanyAsyncValidate}>
            <TextInput
                label="Code"
                source="code"
                validate={required()}/>
        <SimpleForm/>
    <Create/>
  );

translate("Text") not working in asyncValidate for me.

UPD: I have added more code.

1

There are 1 answers

2
konradwww On

You have to get the translate() function into your CompanyAsyncValidate function.
As in documentation: https://marmelab.com/react-admin/CreateEdit.html#validation, this function will be passed with props.translate into your validation function.

However despite of documentation it is not on the 3rd position as argument but on the 2nd.