Question:
What’s wrong with my code? The search/filtering function works fine when I press the search button, but I have the reset button layered right on top of the search button and it’s supposed to appear after the display of the search results. This works fine, but when I press the reset button, which is supposed to reset the page to its original form, nothing happens.
Here’s the code (I tried using chatgpt and claude for help but nothing worked, and this is pretty much my first time using code):
import wixData from 'wix-data';
$w('#resetButton').hide();
let originalDataset = null;
$w.onReady(function () {
// Any additional setup can be added here.
});
export function searchButton_click(event) {
search();
}
function search() {
wixData.query("NewsUpdates")
.contains("headline", $w('#input5').value)
.or(wixData.query("NewsUpdates")
.contains("content", $w('#input5').value))
.find()
.then(results => {
$w('#repeater1').data = results.items;
$w('#resetButton').show();
$w('#resetButton').enable();
$w('#searchButton').hide();
originalDataset = results.items;
})
.catch((error) => {
console.log(error);
});
}
export function resetButton_click(event) {
$w('#repeater1').data = originalDataset;
$w('#input5').value = "";
$w('#searchButton').show();
$w('#searchButton').enable();
$w('#resetButton').hide();
}