Help with setFieldValue

I have a item dynamic page where I made a form.
I’ll hide one of the fields and it must contain the same text of #text6 before save the form.

I’m really bad in JavaScript and have no clue where is the mistake.

The code is:

export function button1_click(event, $w)
{
$w(“#dataset1”).setFieldValue(“codMold”, $w(‘#text6’));

}

But the content of the field comes [object Object]

I know probaly it’s a dumb mistake, but I’ve tried everything i know =(

I 'll really apreciate if some one help =)

Try so:
(“codMold”: $w(’ #text6 '))

Didn’t work =(

I figured it out after a day trying!!!

The code who works it’s

export function button1_click_1(event, $w)
{
//Add your code for this event here:
$w(‘#dataset1’).setFieldValue(“codMold”, $w(‘#text6’).text);
}

Hope to help someone with this information… one day it’s too much time to waste

Your post saved me days of frustration. Thank You!

You just saved me too. As a rookie here, I would have never even thought of that.

Look in the Wix API Reference and it would have given you the answer straight away, along with code samples for it too.

https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue

Givemeawhisky (thanks to him) advised to look in the Wix API Reference. There is a very important rule: “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. "
Therefore add: $w (”#dataset1"). save ();