简体   繁体   English

在React-Admin中点击提交后如何重定向/折叠扩展的编辑表单

[英]How to redirect/collapse an expanded edit form after hitting submit in React-Admin

I am currently trying to collapse the edit form from the list view in React-Admin after hitting the submit button. 我目前正在尝试点击提交按钮后,从React-Admin的列表视图中折叠编辑表单。 I want to be able to view those updated changed in the new list form after hitting submit as well. 我还希望能够在点击“提交”之后查看新列表表单中的更新更新。

Right now I have a class which handles when the form is submitted, and I am using window.location.replace('URL') within that class to try and redirect the page. 现在,我有一个处理提交表单的时间的类,并且在该类中使用window.location.replace('URL')尝试重定向页面。 The problem I am currently running into is that since I want the page to redirect to the same URL, It doesn't show the changes made and also doesn't collapse the edit form. 我当前遇到的问题是,由于我希望页面重定向到相同的URL,因此它不会显示所做的更改,也不会折叠编辑表单。 When I use a different URL and go back to the list view it shows all the changes. 当我使用其他URL并返回列表视图时,它将显示所有更改。 So what I essentially want is to just reload the page (so everything is updated and the edit bar is collapsed) after the form is submitted. 因此,我本质上想要的是在提交表单后重新加载页面(以便进行所有更新并折叠编辑栏)。 However, when I used window.location.reload() , it reloads the page immediately before saving any of the data from the edit form. 但是,当我使用window.location.reload() ,它会在保存来自编辑表单的任何数据之前立即重新加载页面。

This is the code I currently have which handles submit: 这是我当前具有处理提交的代码:

const saveWithNote = (values, basePath, redirectTo) =>
  crudCreate(
    'usergrouprights',
    {
      ...values,
      GroupRights: CalcGroupPermissions(values).rights,
      GroupDenials: CalcGroupPermissions(values).denials
    },
    basePath,
    {
    redirectTo
    }
  );


class SaveWithNoteButtonView extends Component {
  handleClick = () => {
    const { basePath, handleSubmit, redirect, saveWithNote } = this.props;

    return handleSubmit(values => {
      saveWithNote(values, basePath, redirect);
      window.location.replace('/#/usergrouprights');
      // window.location.reload();
    });
  };

  render() {
    const { handleSubmitWithRedirect, saveWithNote, ...props } = this.props;

    return (
      <SaveButton handleSubmitWithRedirect={this.handleClick} {...props} />
    );
  }
}

const SaveWithNoteButton = connect(
  undefined,
  { saveWithNote }
)(SaveWithNoteButtonView);

export default SaveWithNoteButton;

In the list view, I have a custom toolbar which is the following: 在列表视图中,我具有以下自定义工具栏:

const PostEditToolbar = props => (
  <Toolbar {...props}>
    <SaveWithRightsValuesButton />
  </Toolbar>
);

When the code is run, It submits everything properly but I need to manually reload the page to view the changes and for the edit form to collapse as well. 运行代码后,它会正确提交所有内容,但我需要手动重新加载页面以查看更改,并使编辑表单也折叠。 I am unsure if using the window.location.replace or reload call is the right idea as it is not working the way I would like it to at the moment. 我不确定使用window.location.replace或reload调用是否正确,因为它目前无法按我希望的方式工作。

Try adding 尝试添加

redirect="list" redirect =“列表”

to SaveButton : SaveButton

<SaveButton
  handleSubmitWithRedirect={this.handleClick}
  redirect="list"
  {...props}
/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM