I am looking for a way for wixData.update to modify selected fields in the Collection without deleting every other field on the same row.
The collection has 10 fields and I am I am using this code to insert, display or update the Collection data for 3 specific fields ‘q11’, ‘q12’ and ‘q13’.
import wixUsers from 'wix-users';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
$w.onReady(()=> {
if(wixUsers.currentUser.loggedIn){
wixData.query("PreWorkSet1")
.eq('_owner', wixUsers.currentUser.id)
.find()
.then((results)=>{
let items=results.items;
$w('#textBoxQ11').value=items[0].q11;
$w('#textBoxQ12').value=items[0].q12;
$w('#textBoxQ13').value=items[0].q13;
})
}
})
export function button1_click(event) {
let userId = wixUsers.currentUser.id;
wixData.query("PreWorkSet1")
.eq("_owner", userId)
.find()
.then((results) => {
let items = results.items[0];
if (results.items.length === 0){
let toInsertQOnes = {
"q11": $w('#textBoxQ11').value,
"q12": $w('#textBoxQ12').value,
"q13": $w('#textBoxQ13').value
};
wixData.insert("PreWorkSet1",toInsertQOnes)
.then((results2) => {
let items2 = results2;
wixLocation.to("/preworkset1-p2");
})
.catch((err) => {
let errorMsg=err;
})
}
else {
let currentItemId = items._id;
let toUpdateQOnes = {
"_id": currentItemId,
"q11": $w('#textBoxQ11').value,
"q12": $w('#textBoxQ12').value,
"q13": $w('#textBoxQ13').value
};
wixData.update("PreWorkSet1", toUpdateQOnes)
.then((results3) => {
let items3 = results3;
wixLocation.to("/preworkset1-p2");
})
}
})
}
The diplay part within the onReady works perfectly.
I am having problems with the part within ‘button1_click’.
Any time a user submits the data, the three specific fields are inserted or updated perfectly, however, the other 7 fields in the same row get deleted.
How do I get the button1_click to update the 3 fields without deleting the other 7?