marmelab/admin-on-rest

How to provide a custom redirect to a SimpleForm inside Edit ?

christopheblin opened this issue · 2 comments

After an edit, I follow the convention to redirect on the list.

However, I am in a case where I need to provide additional parameters in the list URL.

Is there a way to "cheat" on SimpleForm/Edit to customize the redirect ?

Here is the relevant part of my code :

const ProviderUserEditActions = ({ basePath, data }) => {
  if (! data) return null
  return (
    <CardActions style={cardActionStyle}>
        <ListButton basePath={basePath+'?'+queryString.stringify({providerId:data.providerId, providerName:data.providerName})} />
        <RefreshButton />
    </CardActions>
  );
}

export const ProviderUserEdit = (props) => (
    <Edit actions={<ProviderUserEditActions/>} title={<ProviderUserEditTitle />} {...props}>
        {/*redirect=false will cause the loosing of the URL parameters :(
          but this is the "least worst", because otherwise it would redirect to
          'list' but without URL parameters it will completely crash...
          we hope that someday we will be able to provide our own redirect
          function
          */}
        <SimpleForm redirect={false}>
            <TextInput source="name" />
            <TextInput source="email" />
            <TextInput source="phone" />
            <BooleanInput source="activated" />
        </SimpleForm>
    </Edit>
);
djhi commented

Hi, and thanks for your question. As explained in the react-admin contributing guide, the right place to ask a "How To" question, get usage advice, or troubleshoot your own code, is StackOverFlow.

This makes your question easy to find by the core team, and the developer community. Unlike Github, StackOverFlow has great SEO, gamification, voting, and reputation. That's why we chose it, and decided to keep GitHub issues only for bugs and feature requests.

So I'm closing this issue, and inviting you to ask your question at:

http://stackoverflow.com/questions/tagged/react-admin

And once you get a response, please continue to hang out on the react-admin channel in StackOverflow. That way, you can help newcomers and share your expertise!