如何使用redux-form验证在全局验证中使用翻译

时间:2017-05-26 09:13:54

标签: translation admin-on-rest

尝试使用此代码在全局验证程序中使用验证时:

errors.fieldMissing = [translate('aor.validation.fieldMissing')];

我收到以下错误:

Warning: Failed prop type: Invalid prop `errorText` supplied to `TextField`, expected a ReactNode.

如果没有translation(),只需将错误设置为字符串数组,一切都按预期工作。

如何在全局验证中使用translation()?

1 个答案:

答案 0 :(得分:1)

例如(从AOR example posts编辑):

<SimpleForm defaultValue={{ average_note: 0 }} validate={(values, props) => {
    const errors = {};
    ['title', 'teaser'].forEach((field) => {
        if (!values[field]) {
            errors[field] = [props.translate('aor.validation.required')];
        }
    });
...

翻译和翻译道具的简短例子:

import { translate as translator } from 'admin-on-rest';
const Title = translator(({ record, translate }) => <span>{record ? translate('title.product', { name: record.name }) : ''}</span>);
相关问题