Hello😉!
I have a search bar to search inside my dataset. But is it possible to let people search on the search bar on the home page and bring them to the results page and show the results? Also, would it be possible to show the same searchValue someone searched on the home pages’ search into the results page search bar? Here is my code for my results page.
import wixData from 'wix-data';
$w.onReady( function() {
})
export function button36_click(event) {
let searchValue = $w("#input1").value;
let filter = wixData.filter()
.contains('name', searchValue)
.eq('stat', 'Published')
.or(wixData.filter().contains('title', searchValue)
.eq('stat', 'Published')
)
$w("#dataset1").setFilter(filter);
}
Could someone help me,please?
~Thanks~
Arthur😆
Nop. I got two error messages.
my home page code.
import {local} from 'wix-storige';
import wixLocation from 'wix-location';
$w.onReady(function () {
//TODO: write your page related code here...
});
export function button36_click(event) {
let word = ("#input1").value;
local.setItem("searchValue", word);
wixLocation.to('/free-images')
}
my results page code.
import {local} from 'wix-storage';
import wixData from 'wix-data';
$w.onReady( function() {
var sameword = local.getItem("searchValue");
$w("#input1").value = sameword;
$w("#input1").placeholder = sameword;
$w("#dataset1").onReady(function () {
search();
});
});
export function button36_click(event) {
search();
}
function search() {
wixData.query('Images')
.contains('name',$w("#input1").value)
.eq('stat', 'Published')
.or('title',$w("#input1").value)
.eq('stat','Published')
}
let searchValue = $w("#input1").value;
let filter = wixData.filter()
.contains('name', searchValue)
.eq('stat', 'Published')
.or(wixData.query().contains('title', searchValue)
.eq('stat', 'Published')
)
$w("#dataset1").setFilter(filter);
.find(
.then(res => {
$w("#gallery1").data = res.items;
});
)
}
I got the error messages on the 29th & 31st line of the results page code.
Please help me remove the error messages and enable this function. It would be a shame if I couldn’t have this function as I created a search bar and I just replaced that code with code queens code.
(I always though code queen makes code difficult.)
~Thanks~
Arthur
I will also write my original code for the results page.
import wixData from 'wix-data';
$w.onReady( function() {
})
export function button36_click(event) {
let searchValue = $w("#input1").value;
let filter = wixData.filter()
.contains('name', searchValue)
.eq('stat', 'Published')
.or(wixData.filter().contains('title',searchValue)
.eq('stat','Published')
)
$w("#dataset1").setFilter(filter);
}
If we can’t fix the error on code queens’ code, then I will continue using this code.
~Thanks~
Arthur