Hello! I have to start off by saying I don’t know anything about coding, but I have managed over the last three days to read and piece together some code that is working fairly well with only one issue that I suspect won’t be hard to solve, I’m just not finding the solution. I have a very new appreciation for those of you who write the backend of my sites.
I use Wix Studio. I have a search bar on my home page that displays the search results to a repeater on another page. On the Home page, I enter a keyword in the search bar, that takes me to my results page, the keyword is in the search bar on that page, and the items with that keyword are displayed in the repeater, the item count displayed is correct. If I go back to the Home page and enter another keyword, it takes me to the results page, the search bar on that page has the correct keyword, but the repeater is showing ALL items in the collection. BUT, the item count display is showing the number of items that should be there based on the keyword. If I hit enter in the search bar, the correct items will appear. I can also enter a different key word in the search bar on the results page and it will display correctly.
My code for both pages is below. I apologize if I’m not displaying it correctly. Thank you for any help and insight!
This is the code on my Home page:
import wixData from ‘wix-data’;
import { local} from ‘wix-storage’;
import wixLocation from ‘wix-location’;
export function searchInput_keyPress(event) {
if (event.key===“Enter”){
let word=$w(‘#searchInput’).value;
local.setItem(“searchWord”, word);
wixLocation.to(‘/blank-4’)
}}
This is the code on my results page:
import { local } from ‘wix-storage’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
$w.onReady(function () {
var sameWord = local.getItem(“searchWord”);
$w(“#searchInput”).value = sameWord;
wixData.query('AllFacebookGraphics')
.contains('title', $w("#searchInput").value)
.find()
.then(results => {
$w('#repeater1').data = results.items;
let number = (results.items.length)
if (results.items.length > 1)
$w('#results').text = (number + ' Graphics Found');
if (results.items.length == 1)
$w('#results').text = ('1 Graphic Found.');
if (results.items.length == 0)
$w('#results').text = ('No Graphics Found.');
$w("#repeater1").onItemReady(($item, itemData, index) => {
$item("#sizes").text = itemData.sizes;
$item("#mainImage").src = itemData.mainImage;
$item("#mainImage").link = itemData['link-all-graphics-1-title'];
})
})
$w("#searchInput").onKeyPress((event) => {
if (event.key === "Enter") {
wixData.query('AllFacebookGraphics')
.contains('title', $w("#searchInput").value)
.find()
.then(results => {
$w('#repeater1').data = results.items;
let number = (results.items.length)
if (results.items.length > 1)
$w('#results').text = (number + ' Graphics Found');
if (results.items.length == 1)
$w('#results').text = ('1 Graphic Found.');
if (results.items.length == 0)
$w('#results').text = ('No Graphics Found. Try another keyword.')
$w("#repeater1").onItemReady(($item, itemData, index) => {
$item("#sizes").text = itemData.sizes;
$item("#mainImage").src = itemData.mainImage;
$item("#mainImage").link = itemData['link-all-graphics-1-title'];
})
})
}
})
})