Search.../

save( )

Saves the current item.

Description

The save() function returns a Promise that is resolved to the saved item when:

  • The current item is saved in the collection.
  • Any connected page elements have been updated with the current item’s new values (read & write mode) or a new blank item (write-only mode).

Calling save() on a read-only dataset causes the Promise to reject.

Notes:

  • A dataset needs to load its data before you call its save() function.

    Usually a dataset finishes loading a short time after the page it is on finishes loading. So if you call save() inside the page’s onReady() event handler, the dataset might not be ready yet.

    To call save() as soon as possible after a page loads, use the dataset's onReady() function inside the page’s onReady() event handler to ensure that both the page and the dataset have finished loading.

  • When using a read-write dataset and linked input elements, calling any of the following functions will save any changes made in the linked input elements.

Syntax

function save(): Promise<Object>

save Parameters

This function does not take any parameters.

Returns

Fulfilled - The saved item. Rejected - An error message.

Return Type:

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

Related Content:

Was this helpful?

Save the current item

Copy Code
1$w("#myDataset").save()
2 .then( (item) => {
3 let fieldValue = item.fieldName;
4 } )
5 .catch( (err) => {
6 let errMsg = err;
7 } );
Save the current item when the page loads

Copy Code
1$w.onReady( () => {
2 $w("#myDataset").onReady( () => {
3 $w("#myDataset").save()
4 .then( (item) => {
5 let fieldValue = item.fieldName;
6 } )
7 .catch( (err) => {
8 let errMsg = err;
9 } );
10
11 } );
12
13} );