Search.../

new( )

Deprecated. This function will continue to work, but a newer version is available. Use the add() function instead.

Description

Creates a new blank item.

The new() function saves the current item and then creates 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 new() 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 new() on a read-only dataset causes an error.

Note:

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

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

Syntax

function new(): Promise<void>

new 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 create a new blank item

Copy Code
1// NOTE: This example uses the new add()
2// function, which replaces new().
3// See the function description for more information, and
4// line 14 for the deprecated example.
5
6$w("#myDataset").add()
7 .then( ( ) => {
8 console.log("New item created");
9 } )
10 .catch( (err) => {
11 let errMsg = err;
12 } );
13
14// NOTE: This example uses the deprecated new() function.
15
16 $w("#myDataset").new()
17 .then( ( ) => {
18 console.log("New item created");
19 } )
20 .catch( (err) => {
21 let errMsg = err;
22 } );
Save the current item and create a new blank item when the page loads

Copy Code
1// NOTE: This example uses the new add()
2// function, which replaces new().
3// See the function description for more information, and
4// line 20 for the deprecated example.
5
6$w.onReady( () => {
7 $w("#myDataset").onReady( () => {
8 $w("#myDataset").add()
9 .then( ( ) => {
10 console.log("New item created");
11 } )
12 .catch( (err) => {
13 let errMsg = err;
14 } );
15
16 } );
17
18} );
19
20// NOTE: This example uses the deprecated new() function.
21
22$w.onReady( () => {
23 $w("#myDataset").onReady( () => {
24 $w("#myDataset").new()
25 .then( ( ) => {
26 console.log("New item created");
27 } )
28 .catch( (err) => {
29 let errMsg = err;
30 } );
31
32 } );
33
34} );