Hi there. I’m wanting to set up input fields to update a collection. However I want to overwrite the information in the collection if a field (in this case monthName) is the same as the input being submitted.
I have this code but keep getting an error and can’t work out what I need to do.
Be grateful for any help
import wixData from 'wix-data';
$w.onReady(function () {
$w("#submitButton").onClick(onFormSubmit);
});
function onFormSubmit() {
const monthName = $w("#monthInput").value;
const date = $w("#dateInput").value;
const openTime = $w("#openTimeInput").value;
const closeTime = $w("#closeTimeInput").value;
wixData.query("openingTimes")
.eq("month", monthName)
.find()
.then(results => {
if (results.items.length > 0) {
const existingRecord = results.items[0];
const existingRecordId = existingRecord._id;
wixData.update("openingTimes", existingRecordId, {
month: monthName,
date: date,
openTime: openTime,
closeTime: closeTime
})
.then(() => {
console.log("Record updated successfully");
})
.catch(error => {
console.log(error);
});
} else {
wixData.insert("openingTimes", {
month: monthName,
date: date,
openTime: openTime,
closeTime: closeTime
})
.then(() => {
console.log("New record created successfully");
})
.catch(error => {
console.log(error);
});
}
})
.catch(error => {
console.log(error);
});
}
The error is here
wixData.update(“openingTimes”, existingRecordId, {
month: monthName,
date: date,
openTime: openTime,
closeTime: closeTime
})
and I get this error message
Argument of type ‘{ month: string; date: Date; openTime: string; closeTime: string; }’ is not assignable to parameter of type ‘WixDataOptions’. Object literal may only specify known properties, and ‘month’ does not exist in type ‘WixDataOptions’.
Many thanks for any help