hello guys i’m having a hard time figuring this one out! i tried this code below and it works fine elsewhere on another page! which is strange?
$w.onReady(function () {
$w("#profileSearch").onReady( () => {
$w("#repeater5").onItemReady( ($item, MemberProfile, index) => {
$item("#contact5").link = 'mailto:' + MemberProfile.email;
}
);
} );
} );
this is the whole page code
import { session } from 'wix-storage';
import wixData from 'wix-data';
import wixLocation from 'wix-location';
let searchAgain, searchIcon, mentionTraderTxt, noTradersFound, listSize,
currIndex = -1;
const HL_COLOR = "rgba(61,155,233)";
const REG_COLOR = "rgba(243,243,243)";
$w.onReady(function () {
mentionTraderTxt = $w('#mentionTraderTxt');
noTradersFound = $w('#noTraderFound');
searchAgain = $w('#searchAgain');
searchIcon = $w('#searchIcon');
$w('#repeater5').data = [];
let trade = session.getItem("trader");
if (trade) {
$w("#input2").value = trade;
$w("#input2").placeholder = trade;
$w('#profileSearch').onReady(() => search());
}
$w('#searchBar2').onKeyPress((event) => {
setTimeout(() => {
if ($w('#searchBar2').value.length === 0) {
currIndex = -1;
$w("#rptDropdown").collapse()
.then(() => {
console.log("Done with collapse");
});
} else {
switch (event.key) {
case "Enter":
$w('#searchBar2').value = $w('#rptDropdown').data[currIndex].towns;
$w("#rptDropdown").collapse()
.then(() => {
console.log("Done with collapse");
});
break;
case "ArrowLeft":
case "ArrowRight":
break;
case "ArrowUp":
if (currIndex > 0) {
currIndex -= 1;
refresh_repeater();
}
break;
case "ArrowDown":
if (currIndex < listSize - 1) {
currIndex += 1;
refresh_repeater();
}
break;
case "Escape":
$w('#searchBar2').value = '';
currIndex = -1;
$w("#rptDropdown").collapse()
.then(() => {
console.log("Done with collapse");
});
break;
default:
currIndex = -1;
wixData.query("Uk-towns-list")
.startsWith("towns", $w('#searchBar2').value)
.ascending("towns")
.limit(5)
.find()
.then((res) => {
$w('#rptDropdown').data = [];
$w('#rptDropdown').data = res.items;
listSize = res.items.length;
$w('#rptDropdown').expand();
});
break;
}
}
}, 50)
});
});
export function search_click() {
search();
runSearch();
}
function search() {
wixData.query('MemberProfile')
.contains('traderBusinessName', $w("#input2").value)
.find()
.then(res => {
$w('#repeater5').data = res.items;
$w('#repeater5').expand();
if (res.items.length > 0) {
} else {
noTradersFound.expand();
searchAgain.expand();
searchIcon.expand();
mentionTraderTxt.collapse();
}
});
}
export function searchButton_click(event) {
let word = $w("#searchBar").value;
let words = $w("#searchBar2").value;
session.setItem("searchWord", word);
session.setItem("searchWords", words);
wixData.query("Search-Stats").find().then((result) => {
let SearchStatsitems = result.items[0]; //item with values
let id = SearchStatsitems._id; // this will be used for
//writing data back
SearchStatsitems.traderSearches++;
// increment field with yes by 1
// write updated value back to collection
wixData.update("Search-Stats", SearchStatsitems).then(() => {
// refresh dataset to show new value
//(this should be done in promise,
//after updating collection)
$w("#dataset2").refresh();
wixLocation.to(`/user-profile-data`);
}
)})}
export function rptDropdown_itemReady($item, itemData, index) {
$item('#name').text = itemData.towns;
if (index === currIndex) {
$item("#rptBox").style.backgroundColor = HL_COLOR;
} else {
$item("#rptBox").style.backgroundColor = REG_COLOR;
}
$item('#container1').onClick(() => {
$w('#searchBar2').value = itemData.towns;
$w('#rptDropdown').collapse();
});
}
function refresh_repeater() {
$w("#rptDropdown").forEachItem(($item, itemData, index) => {
$item('#name').text = itemData.towns;
if (index === currIndex) {
$item("#rptBox").style.backgroundColor = HL_COLOR;
} else {
$item("#rptBox").style.backgroundColor = REG_COLOR;
}
$item('#container1').onClick(() => {
$w('#searchBar2').value = itemData.towns;
$w('#rptDropdown').collapse();
});
});
}
function runSearch(){
let word = $w("#searchBar").value;
let words = $w("#searchBar2").value;
session.setItem("searchWord", word);
session.setItem("searchWords", words);
wixData.query("Search-Stats").find().then((result) => {
let SearchStatsitems = result.items[0]; //item with values
let id = SearchStatsitems._id; // this will be used for
//writing data back
SearchStatsitems.traderSearches++;
// increment field with yes by 1
// write updated value back to collection
wixData.update("Search-Stats", SearchStatsitems).then(() => {
// refresh dataset to show new value
//(this should be done in promise,
//after updating collection)
$w("#dataset2").refresh();
wixLocation.to(`/user-profile-data`);
})})
}
$w.onReady(function () {
$w("#searchBar2").onKeyPress( (event) => {
if(event.key === "Enter"){
runSearch();
}
})
});
$w.onReady(function () {
$w("#profileSearch").onReady( () => {
$w("#repeater5").onItemReady( ($item, MemberProfile, index) => {
$item("#contact5").link = 'mailto:' + MemberProfile.email;
}
);
} );
} );