user3646212
user3646212

Reputation: 89

React Admin: onSuccess does not work properly on <Edit> Component

onSuccess function does not work properly on react-admin,

my code:

const onSuccess = () => {
   redirect('list', props.basePath);
};


<Edit 
  onFailure={onFailure}  
  onSuccess={onSuccess}  
  title="Ediar Usuário" 
  {...props} 
>
  <SimpleForm 
     variant="standard" 
     toolbar={<CustomToolbar />} 
  >
</Edit>

On the first time, it works perfectly but at second time, nothing happens.

Do not even trigger the save event

Upvotes: 5

Views: 2073

Answers (3)

Kia Kaha
Kia Kaha

Reputation: 1801

Having the same issue I came across this issue on the react-admin github page. So basically it is not a bug but ... kinda feature the way the Edit component works. In short:

const onSuccess = () => {
     ...
     notify('success', 'info', null, true);
     ...
}

This is the way you should call notify inside your custom onSuccess function to trigger the real update on the dataProvider.

Upvotes: 0

Hyungju Moon
Hyungju Moon

Reputation: 141

I am suffering from the same problem.

Jasper Bernales's tip was effective.

I've changed my code from :

<Edit
      onSuccess={onSuccess}
      {...props}
    >

to :

<Edit
      onSuccess={onSuccess}
      undoable={false}
      {...props}
    >

then ...it works!

It seems like a problem caused by forcing "useRedirect" or "useRefresh" to interfere with the delay scheduled by "undoable".The document seems to need an update to this part. just check this out from React-Admin Docs.:

You can disable this behavior by setting undoable={false}. With that setting, clicking on the Delete button displays a confirmation dialog. Both the Save and the Delete actions become blocking and delay the refresh of the screen until the data provider responds.

Upvotes: 1

Jasper Bernales
Jasper Bernales

Reputation: 1681

I don't know if this is applicable to your use case but setting undoable to false on Edit component works

Upvotes: 3

Related Questions