Question:
[Tengo una base de datos con nombres con tildes y otros sin tildes. Quiero en un buscador poder encontrar los productos. cree un codigo para poder buscarlos pero a la hora de escribir las palabras con tilde, si no las escribo como están en mi colección entonces no las encuentra. o sea con tilde.]
import wixData from ‘wix-data’;
$w.onReady(() => {
// Real-time search as the user types in the search bar.
$w(“#SearchbarHome”).onInput(() => {
performSearch();
});
});
function performSearch() {
const searchQuery = $w(“#SearchbarHome”).value.trim();
if (searchQuery.length > 0) {
// Apply the filter based on the search query
$w("#dataset1").setFilter(
wixData.filter()
.eq("name", searchQuery)
.or(wixData.filter().contains("description", searchQuery))
.and(wixData.filter().ne("autorizacion", true))
)
.then(() => {
console.log("Dataset filtered");
// Update the repeater visibility after the filter is applied
updateRepeaterVisibility();
})
.catch((err) => {
console.error("Failed to filter dataset:", err);
// Collapse the repeater and show the notFound element if there's an error
$w("#repeaterSearch").collapse();
});
} else {
// Clear the filter and collapse the repeater if search query is empty
$w("#dataset1").setFilter(wixData.filter())
.then(() => {
console.log("Filter cleared");
$w("#repeaterSearch").collapse();
})
.catch((err) => {
console.error("Failed to clear filter:", err);
// Collapse the repeater and hide the notFound element if there's an error
$w("#repeaterSearch").collapse();
});
}
}
function updateRepeaterVisibility() {
// Check if the dataset has items to display after filtering
$w(“#dataset1”).getItems(0, 1).then((results) => {
if (results.totalCount > 0) {
$w(“#repeaterSearch”).expand();
// Hide the notFound element when there are items to display
} else {
$w("#repeaterSearch").collapse();
// Show the notFound element when there are no items to display
}
}).catch((err) => {
console.error("Failed to get items from dataset:", err);
// Collapse the repeater and show the notFound element if there's an error
$w("#repeaterSearch").collapse();
});
}