Search.../

setFieldValue( )

Updates the value of a field in the current item.

Description

The setFieldValue function sets the value of a field in the current item. Setting a field value fires an onItemValuesChanged event when the page elements connected to the field have been updated with the new value.

Setting the value of a field in a dataset item does not immediately set that value in the collection that the dataset is connected to. You still need to call the dataset save() function or any other function that performs a save to have the new value reflecting in the collection.

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

Note:

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

To call setFieldValue() 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 setFieldValue(fieldKey: string, value: *): void

setFieldValue Parameters

NAME
TYPE
DESCRIPTION
fieldKey
string

The field ID of the field to update.

value
*

The new value.

Returns

This function does not return anything.

Return Type:

void
Mixed in from:wix-dataset.Dataset

Related Content:

Was this helpful?

Set a field's value

Copy Code
1$w("#myDataset").setFieldValue("title", "New Title");
Set a field's value and save the item to the connected collection

Copy Code
1$w("#myDataset").setFieldValue("title", "New Title");
2$w("#myDataset").save();
Set a field's value when the page loads

Copy Code
1$w.onReady( () => {
2 $w("#myDataset").onReady( () => {
3 $w("#myDataset").setFieldValue("title", "New Title");
4
5 } );
6
7} );