A slightly strange one in that I have basically re-designed a section of my website today. The dataset remains the same, I have just amended how the page works and how the data is shown. Part of the page is to show a 'photo credit' using a text box on photo's which have been supplied by other people and on the old page I had this working fine but now on the new page, even though I have used the same code, it is not working :(
The code for the page is as below:
import wixLocation from 'wix-location';
import wixData from 'wix-data';
$w.onReady(function () {
uniqueDropDown1();
NumberChange();
CreditTextShow();
});
function uniqueDropDown1 (){
wixData.query("LocoLogs")
.ascending('class')
.limit(1000)
.find()
.then(results =>{
const uniqueTitles = getUniqueTitles(results.items);
$w('#classDropDown').options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.class);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList){
return uniqueList.map(curr => {
return {label:curr, value:curr};
});
}
}
export function classDropDown_change(event, $w){
uniqueDropDown2();
$w('#numberDropDown').enable();
$w('#numberDropDown').value = null;
$w('#box9').collapse();
$w('#box10').collapse();
$w('#text356').collapse();
$w('#text472').collapse();
$w('#button15').collapse();
$w('#image14').collapse();
$w('#box8').collapse();
$w('#repeater1').collapse();
}
function uniqueDropDown2(){
wixData.query('LocoLogs')
.contains("class", $w('#classDropDown').value)
.ascending('number')
.limit(1000)
.find()
.then(results =>{
const uniqueTitles = getUniqueTitles(results.items);
$w('#numberDropDown').options = buildOptions(uniqueTitles);
});
function getUniqueTitles(items) {
const titlesOnly = items.map(item => item.number);
return [...new Set(titlesOnly)];
}
function buildOptions(uniqueList) {
return uniqueList.map(curr =>{
return {label:curr, value:curr};
});
}
}
function NumberChange () {
$w('#numberDropDown').onChange((event) => {
let number = $w('#numberDropDown').value;
$w('#dynamicDataset').onReady(() => {
console.log("The dataset is ready to be filtered.");
$w('#dynamicDataset').setFilter(wixData.filter()
.eq("number", number)
)
.catch((err) => {
console.log(err);
});
});
});
}
function CreditTextShow () {
let activeDynamicItem = $w('#dynamicDataset').getCurrentItem();
let fieldX = activeDynamicItem['photoCredit'];
if (fieldX && fieldX === "Joe Bloggs") {
$w('#text488').show();
} else {
$w('#text488').hide();
}
}
export function numberDropDown_change(event) {
$w('#box9').expand();
$w('#box10').expand();
$w('#text356').expand();
$w('#text472').expand();
$w('#button15').expand();
$w('#image14').expand();
$w('#box8').expand();
$w('#repeater1').expand();
}
export function button15_click_1(event) {
$w('#text484').expand();
$w('#text482').expand();
$w('#text485').expand();
$w('#text483').expand();
$w('#image15').show();
$w('#image14').collapse();
$w('#button14').show();
$w('#button15').hide();
$w('#text488').collapse();
}
export function button14_click(event) {
$w('#text484').collapse();
$w('#text482').collapse();
$w('#text485').collapse();
$w('#text483').collapse();
$w('#image15').hide();
$w('#image14').expand();
$w('#button14').hide();
$w('#button15').show();
$w('#text488').expand();
}
All aspects of the code work except for the CreditTextShow function even though I have used the same code that has worked so well on the old version of the page.
Could anyone please point me in the right direction with this one please?
Thanks
Hello friend, I looked at your code and it could use some refactoring (reorganization an rewriting codes to be more readable and short).
Unfortunattely, I couldn't understand the problem you are facing, if you could explain it better, I would appreciate.