Search.../

onBeforeSave( )

Adds an event handler that runs just before a save.

Description

The onBeforeSave() function allows you to optionally perform actions right before a save() operation. When you call save(), the callback is run before the save operation. Any validity checks on the data are run after the callback runs. If the callback function returns false, returns a rejected Promise, or throws an error, the save operation is canceled.

Calling onBeforeSave() on a read-only dataset causes an error.

Note: onBeforeSave() runs before any input element validations.

Syntax

function onBeforeSave(handler: BeforeSaveHandler): void
handler: function BeforeSaveHandler(): Promise<boolean>

onBeforeSave Parameters

NAME
TYPE
DESCRIPTION
handler

BeforeSaveHandler

The before save event handler.

Returns

This function does not return anything.

Return Type:

void

BeforeSaveHandler Parameters

This function does not take any parameters.

Returns

Fulfilled - Indication whether to continue with save.

Return Type:

Promise<boolean>
Mixed in from:wix-dataset.Dataset

Was this helpful?

Register a callback to run before a save and continue with the save

Code Example

Copy Code
1$w("#myDataset").onBeforeSave( () => {
2 console.log("Continuing save");
3} );
Register a callback to run before a save and cancel the save

Code Example

Copy Code
1$w("#myDataset").onBeforeSave( () => {
2 console.log("Canceling save");
3 return false;
4} );