Search.../

add( )

Adds a new blank item.

Description

The add() function saves the current item and then adds a new blank item. When the editing of the new item is complete, you will need to call another function that will save the new item.

The index of the new item is one after the index of the current item, or zero if there is no current item.

Note that since the add() function begins by saving the current item, if the current item cannot be saved for any reason, such as it does not pass validation, calling the function will cause an error.

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

Notes:

A dataset needs to load its data before you call its add() function. Usually a dataset finishes loading a short time after the page it is on finishes loading. So if you call add() inside the page’s onReady() event handler, the dataset might not be ready yet.

To call add() 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.

This function replaces the deprecated new() function. The deprecated function will continue to work, but will not receive updates.

Syntax

function add(): Promise<void>

add Parameters

This function does not take any parameters.

Returns

Fulfilled - When a new empty item is the current item of the dataset. Rejected - An error message.

Return Type:

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

Was this helpful?

Save the current item and add a new blank item

Copy Code
1$w("#myDataset").add()
2 .then( ( ) => {
3 console.log("New item added");
4 } )
5 .catch( (err) => {
6 let errMsg = err;
7 } );
Save the current item and add a new blank item when the page loads

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