onAfterSave question

I put a gif-spinner on the onBeforeSave. I take it away on the onAfterSave. Turns out when the data is not dirty, nothing is saved, onAfterSave is not called and the spinner is not taken down.
Doc is rather sparse on this item. Could anyone tell me how to catch a no save in the onAfterSave or whatever?

We indeed don’t fire the onAfterSave event in case a save didn’t occur.
This can happen in one of two cases:

  1. There was nothing to save (the current item is not modified)
  2. The save was canceled due to a “onBeforeSave” callback that returned false or a rejected promise.
  3. There was an unexpected error

The second case is irrelevant because you control it, so you can know to hide the spinner.
For the third case, register to the dataset " onError " event and hide the spinner when the event is raised with “operationName” set to “save”.

For the first case, what you can do is add a boolean variable in your code called “isItemChanged” and register to the dataset " onItemValuesChanged " event. Whenever the event is raised, change the variable to true. This will tell you that the dataset will perform a save operation when requested.
In your onBeforeSave code, if the variable is set to false, you know that a save will not occur.

We will think about adding a new event, maybe something like “onSaveCancelled”, to help with such cases.

Thanks Tomer, I will try to do this, I will first have to read up.

1 Like

I did something similar and posted my solution here: https://www.wix.com/corvid/forum/community-discussion/solved-how-to-disable-submit-button-if-there-s-no-change

I didn’t use onBeforeSave, rather I used the button click to start the spinner. But I did use a boolean and disable the spinner onAfterSave .