How would you clear a cms field/changes its value by clicking a button.
I want to let people update their offer (the green part) which would then need to reset the black part and clear the “status” and “seller response.” Both Green and Black parts are connect to the same collection and data set.
something similar to this maybe
import wixData from 'wix-data';
import wixWindow from 'wix-window';
$w.onReady(function () {
// Ensure your dataset ID is set properly
$w('#myDataset').onReady(() => {
// Button click event
$w('#updateOfferButton').onClick(async () => {
// Get the current item from the dataset
const currentItem = $w('#myDataset').getCurrentItem();
// Check if there is an item to update
if (currentItem) {
// Update the fields to clear values
currentItem.status = ""; // Clearing the Status field
currentItem.sellerResponse = ""; // Clearing the Seller's Response field
// Update the dataset with the new values
try {
await wixData.update('yourCollectionName', currentItem);
$w('#myDataset').refresh(); // Refresh the dataset to reflect the changes
wixWindow.openLightbox("Success", { message: "Offer updated successfully!" });
} catch (error) {
console.error("Failed to update offer:", error);
wixWindow.openLightbox("Error", { message: "Failed to update the offer. Please try again." });
}
}
});
});
});