[RESOLVED] wixData.update updates field of the top row only


Hello.

I have collection named acik_pozisyonlar. I show some of the fields of this on a page. While doing this I filter the results according to a dropdown menu. To do this I use the code below. I have no problem doing this:

$w.onReady( function () {
});
import wixData from ‘wix-data’;
export function dropdown1_change(event, $w) {
wixData.query(‘acik_pozisyonlar’)
.eq(‘pozisyon_kodu_adi’, $w(‘#dropdown1’).value)
.find() // Run the query
.then(res => {
// Set the table data to be the results of the query
let veriler = res.items[0];;
$w(‘#pozekletxtbox2’).value = veriler.pozisyon_adi;
$w(‘#pozekletxtbox3’).value = veriler.pozisyon_seviyesi;
$w(‘#pozekletxtbox4’).value = veriler.pozisyon_aciklamasi;
$w(‘#dropdown2’).value = veriler.pozisyonSahibiMusteri;
$w(‘#input1’).value = veriler._id;
});
}

Then I change the value of the dropdown menu to the value corresponding to the field which is on second row of the collection. Data regarding the 2nd row (the fields I want to display) is displayed successfully. Then I change only one of the text of fields. The problem arises; when I want to submit the change to the collection using a submit button. I expect the field of the 2nd row to be updated (id is correct) but the field of the first row is updated every time. My code to upadate code is below:

export function button1_click(event, $w) {
let poz_adi_kodu = $w(‘#dropdown1’).value;
let toUpdate = {
“_id”: $w(‘#input1’).value,
“pozisyon_adi”: $w(‘#pozekletxtbox2’).value,
“pozisyon_seviyesi”: $w(‘#pozekletxtbox3’).value,
“pozisyon_aciklamasi”: $w(‘#pozekletxtbox4’).value,
“pozisyonSahibiMusteri”: $w(‘#dropdown2’).value,
“pozisyon_kodu_adi”: poz_adi_kodu
};

wixData.update(“acik_pozisyonlar”, toUpdate)
.then( (results) => {
let item = results; //see item below
} )
. catch ( (err) => {
let errorMsg = err;
} );
}
My collection is connected to a normal Dataset. And my submit button is connected to the same Dataset.

I stuck on this issue. I will be glad if anyone can help.
Regards,

If you add action submit to a button you cant add another click event as you have done in your code. Take away the Submit on the button connected to the dataset and only use your code, then it will work.

Andreas thanks alot for the quick response. This info is very valuable. Actually it still didn’t work in the first place. Nothing changed in the collection. But then I changed the fieldname pozisyon_kodu_adi to pozisyon_kodu in below code.

.eq(‘pozisyon_kodu_adi’, $w(’ #dropdown1 ').value)

And also I took away submit action from the Button as you said; it worked.
I think the issue was that: The first field I used (pozisyon_kodu_adi) was a field created by beforeInsert function (I concatenated 2 fields) . Probably a field merged with beforeInsert somehow blocks update command.

Thanks.