在v3中提交后如何重置SimpleForm值

时间:2019-12-10 12:24:58

标签: react-admin

我有一个带有SimpleForm的自定义页面。提交表单后,我需要停留在同一页面上,但想清除表单。

是否有一种简单的方法可以在提交后重置SimpleForm值?

这是我的组件的外观:

import React from 'react';
import { useDispatch } from 'react-redux';
import Card from '@material-ui/core/Card';
import CardContent from '@material-ui/core/CardContent';
import { Title, SimpleForm, FileInput, FileField, required, useNotify } from 'react-admin';

const MyCustomPageComponent = () => {
  const dispatch = useDispatch();
  const notify = useNotify();

  const handleSave = record => dispatch(myCustomAction(record));

  return (
    <Card>
      <Title title="...." />
      <CardContent>
        <SimpleForm save={handleSave}>
          <FileInput
            source="someFile"
            validate={required()}
            multiple={false}
          >
            <FileField source="src" title="title" />
          </FileInput>
        </SimpleForm>
      </CardContent>
    </Card>
  )
};

const myCustomAction = (record) => ({
  type: 'MY_CUSTOM_ACTION',
  payload: { ...record },
  meta: {
    fetch: 'MY_CUSTOM_FETCH',
    resource: 'SomeResource',
    redirect: false,
    onSuccess: {
      notification: {
        body: 'Success message',
        level: 'info',
      },
    },
    onFailure: {
      notification: {
        body: 'Error message',
        level: 'warning',
      },
    },
  },
});

0 个答案:

没有答案