Want to "call" multiple items from database according to user selection. Can you help?

Hi @russian-dima !
Indeed! I’ve learned tons!!! For a newbie like me it has been a ride!

Filtering through the boolean PassCo is priority, so in order to be able to deliver, I’ve ended up doing it the “old fashion” way without code.
It isn’t as nice, but it delivers the purpose and doesn’t load any other initiatives information that shouldn’t be displayed on that page.

Nevertheless, it has been useful for a page that was pretty lame and just displays everyones info, and now it looks great!

Hope you are having a nice day #takecare

Hi @russian-dima !
Im so sorry to bug you with this.
Not sure how or why, things suddenly stopped “working” (selection tags, filters etc).
So we redid the whole thing and we messed it up.
I believe we haven’t set things in the right place :frowning:
Yeah I know… :frowning:

This is the current situation.
Reset btns are not reseting
Input search box is not filtering

// Checks if the current item has a value in the field

Is not actually “checking”.
It does display the URL but not the image.
For example here,it should display the facebook image/icon.

Not sure what we have done wrong.
Your advice and helpis deeply appreciated!!!


import wixData from 'wix-data';
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';


var refFields = []
//--------- USER-INTERFACE ---------------------
var DATASET     = "#dataset1"
var TABLE       = "#table1"
var REPEATER    = "#repeater1"
var DATABASE    = "DatosPerfil"
//-------------------------------
var REFERENCE1  = "actividad" 
var REFERENCE2  = "provincia" 
var REFERENCE3  = "colaborador"
var REFERENCE4  = "tipoActividad"
//--------- USER-INTERFACE ---------------------
 
let debounceTimer;

$w.onReady(async function () {
    $w(DATASET).onReady(() => {
 // Gets the current item properties and stores them in a variable called item
 const item = $w(DATASET).getCurrentItem();
 // Checks if the current item has a value in the field
 if (!item.imada) {$w("#ImEmbajada").hide();}
 if (!item.imor) {$w("#ImEmbajador").hide();}

if (!item.fbEmpresa) {$w("#FBimage").hide();}
if (!item.instagramEmpresa) {$w("#INSTempresa").hide();}
if (!item.youtubeEmpresa) {$w("#YTempresa").hide();}
if (!item.twitter) {$w("#TWempresa").hide();}
if (!item.linPersonal) {$w("#LINKPersonal").hide();}
if (!item.linEmpresa) {$w("#LINEmpresa").hide(); }
if (!item.url) {$w("#web").collapse();}

let count = $w("#dataset1").getTotalCount();
        $w("#resultCounter").text = '' + count;});
    });

$w("#searchInput").onKeyPress( (event) => {
        if (debounceTimer) {
            clearTimeout(debounceTimer);
            debounceTimer = undefined;
        }
        // Provide a 350 millisecond interval to allow the site visitor to finish typing
        debounceTimer = setTimeout(() => {
            filter($w("#searchInput").value);
        }, 350); 
    });

    
    $w("#BuscarBtn").onClick( (event) => {
        filter();
        $w("#searchInput").value = undefined;
    });

let lastFilterName;

async function filter(name) { 

    if(lastFilterName !== name) {
        let newFilter = wixData.filter();

        if(name)
        newFilter = newFilter.contains('sobreMi1', name);
        
        
        await $w("#dataset1").setFilter(newFilter);
        
        let count = $w("#dataset1").getTotalCount();
        $w("#resultCounter").text = '' + count;
        setVariables(name);
    }
}

function setVariables(name) {
    lastFilterName = name;
}



        refFields=[REFERENCE1, REFERENCE2, REFERENCE3, REFERENCE4]
 
 //Options for CheckBox-1--------------------------------------------------------------
        $w('#CB1').options = [
            {"label": "Embajadores",    "value": "Embajador"},
            {"label": "Embajadas",      "value": "Embajada"},
        ];
 //Options for CheckBox-2--------------------------------------------------------------
        $w('#CB2').options = [
            {"label": "Online",    "value": "Online"},
            {"label": "Presencial",      "value": "Presencial"},
            {"label": "Presencial y Online",      "value": "Presencial y Online"},
        ];

 //Create-Unique-Dropdown--------------------------------------------------------------
        wixData.query(DATABASE)
        .limit(1000)
        .find()
        .then(results => {
 const uniqueTitles1 = getUniqueTitles1(results.items);
 const uniqueTitles2 = getUniqueTitles2(results.items);
            $w("#DD1").options = buildOptions1(uniqueTitles1);  //---> ACTIVIDAD
            $w("#DD2").options = buildOptions2(uniqueTitles2);  //---> PROVINCIA
        });

 //Dropdown_Buttons--------------------------------------------------------------------
        $w('#DD1, #DD2').onChange(()=>{SEARCH_ENGINE();});
 //Checkbox_Buttons--------------------------------------------------------------------
        $w('#CB1').onChange(()=>{SEARCH_ENGINE();});
        $w('#CB2').onChange(()=>{SEARCH_ENGINE();});
 //Search_Buttons----------------------------------------------------------------------
        $w('#BuscarBtn').onClick(()=>{ SEARCH_ENGINE(); });
 //Reset_Buttons-----------------------------------------------------------------------
        $w('#btnReset1').onClick(()=>{$w("#DD1").selectedIndex=undefined, SEARCH_ENGINE();});
        $w('#btnReset2').onClick(()=>{$w("#DD2").selectedIndex=undefined, SEARCH_ENGINE();});


 //Datos de Tags
    $w(REPEATER).onItemReady(($item, itemData, index) => {
 let options = [];
 let tags = itemData.tipoActividad; console.log("Tags: ", tags)
 let tagLength = tags.length; console.log("Tag-Length: ", tagLength)
        console.log("Item-Data: ", itemData)
        console.log("Index: ", index)
 
 if(tagLength!==undefined){   
 for(var i=0; i<tagLength; i++){        
                options.push({"label": tags[i],"value": tags[i]})
                $item("#selectionTags1").options = options;
            }
        }
    });

 ///EMAIL BTN
    $w('#btnemail').onClick(()=>{
        wixLocation.to("mailto:") + $w(DATASET).getCurrentItem().emailDeContacto.id
    });



//------------- Functions ------------------------------------------------------------
function getUniqueTitles1(items)    {const titlesOnly = items.map(item => item[refFields[0]]); return [...new Set(titlesOnly)];}
function buildOptions1(uniqueList1) {return uniqueList1.map(curr => {return {label:curr, value:curr};});}
//-------------
function getUniqueTitles2(items)    {const titlesOnly = items.map(item => item[refFields[1]]);  return [...new Set(titlesOnly)];}
function buildOptions2(uniqueList2) {return uniqueList2.map(curr => {return {label:curr, value:curr};});}
//-------------
 
function SEARCH_ENGINE() {console.log("Search-Engine started")
 let filter  = wixData.filter()  
 //DropDowns-------------------------------
 let item1   = $w('#DD1').value //---> DropDown
 let item2   = $w('#DD2').value //---> DropDown
 //Checkbox-Group--------------------------
 let item3   = $w('#CB1').value //---> CheckBox 
 let item4   = $w('#CB2').value //---> CheckBox 

 //DropDowns-------------------------------
 if (item1) {filter = filter.eq(REFERENCE1, item1)}
 if (item2) {filter = filter.eq(REFERENCE2, item2)}
 
 //Checkbox-Group--------------------------
 if (item3) {for(var i=0; i<item3.length; i++) {filter = filter.eq(REFERENCE3, item3[i])}}
 if (item4) {for (var i=0; i<item4.length; i++) {filter = filter.eq(REFERENCE4, item4[i])}}

    $w(DATASET).setFilter(filter)
    .then(()=>{result_COUNTER()
        $w(TABLE).refresh();
    })
}
 
function RESET () {
    $w("#DD1").selectedIndex = undefined;
    $w("#DD2").selectedIndex = undefined;
    $w('#CB1').value = undefined;
    $w('#CB2').value = undefined;
}

//Result-Counter----------------------------------------------
function result_COUNTER() {
 let count = $w(DATASET).getTotalCount().toString();
    console.log("COUNT = " + count)
    $w('#resultCounter').text = count.toString()
} 


THANK YOU!!!

@hola95401
Without knowing why it suddenly stopped working for you, your further steps could be the following…

  1. create a copy of the damaged site 2) open the site-history to go back in time to reload an oder version of your site.
  2. you can also try to remember which changes were done, before the issue happened.
  3. Try to analyse step by step your code and it’s functions by using the console.

What does work and what doesnt?
Sorry to say, that i am at the Moment totaly overloaded, because searching for solutions myself. But i try to take a look if i find some freetime.

Hi @russian-dima !
Ive opened a ticket with the support team as some collections are getting empty and very crazy stuff is happening on the preview and Live versions.

We cannot go back to a previous site version as we have also been moving forward with some other sections. Total chaos.

We had no copy of the code besides the one posted here, and I had been working on the search input and the hide and show elements (that was working by then),but I have no clue what I have made different that currently doesn’t filter. I think I have messed up the order.

Im sorry to hear you are overloaded. I really hope I could give you a hand.
Let me know if I can help you out.

Thanks for your offered help.:sweat_smile:
A little Tipps for you.

Always generate site dublicate-, when everything works 100% and you ever will be in such an situation again.

I once die the same falls, till i started using → site-versions (dublicate well working sites for security reasons and situatio like yours).

The history is ok, but is difficult to handle.

But what you still can do is to find a checkpoint in your history, where your projects works well and compare it with your actual working one. But first —> generate a DUBLICATE!

Or you wait for reply from Wix-customer service.

I’ll be waiting for wix- customer service reply on whats happening on the crazy stuff. Not possible to go back to an older version. Too many things have been modified since this hectic things begun.

Lesson learned.
Once I get this running again I’ll make a duplicate.

Do you see something wrong with the code I shared?
Thank you!!!

Ok let’s do some improvements…

At the first look the first thing i have checked was your DATASET-VARIABLE.
You do not use it consequently, this can make issues when doing it like you do.

I gave you a kind of —> USER-INTERFACE <— where you can manage easely all given and important variables, which are used alater somwhere in your (already grown-up code). Why is my suggested technique useful ???

Do you have already some ideas? No?

Ok, than let us say you have the variable —>

var DATASET = 

And you also gave your DATASET-variable a VALUE → “#dataset1

DATASET="#dataset1"

But when i look at your code, some parts uses the VARIABLE and some parts are hard-coded in the code. Every part of your code, which is hardcoded, can include (for example → TYPING-ERRORs).

You already have any idea, what i want to tell you ?

Second one what i see is → you do not have any console-logs!
How you want to find your bug, when you are not able to see what happens in CODE ?

Add almost in every code-line a understanable console.log → to investigate your own code. Then you will be able to find emidiately the issue in your code.

How to do ?

Start with a simple console.log…here your code starts…

$w.onReady(async function () {console.log("CODE-START")
  $w(DATASET).onReady(() => {console.log("Dataset-Ready")
  // Gets the current item properties and stores them in a variable called item
  const item = $w(DATASET).getCurrentItem(); console.log("MyCurrentItem: ", item)
  // Checks if the current item has a value in the field
  if (!item.imada) {$w("#ImEmbajada").hide();}
  if (!item.imor) {$w("#ImEmbajador").hide();}
  .
  .
  .
  .
  .

Take a look onto the first implemented console-log.
Take a look onto the second implemented console-log.
Take a look onto the third implemented console-log.

If your code is not running, then it brakes somewhere on runtime, but before it breaks at a specific code-line, it will show you all the well running code-lines, with the help of the CONSOLE !

Now try to investigate your code by yourself and create console-logs at important code-lines (or even at every-code-line), to find out, at which part of your code all breaks down and you get an —> ERROR.

Good luck and happy DEBUGGING! :wink:

I’m sorry @russian-dima ,
This is what I have understood :frowning:

对不起朋友。我一点都不明白。

I understand. Then i would say…
好,我懂了。 然后,您可能依赖于Wix支持的帮助。
或者你可以雇用我😉

Indeed!!!
This is what I have up with

仍在等待Wix支持。我们有大约5张公开门票。console.log (“waiting”)
如果我还没有联系过你,我不知道你的真实姓名 console.log (“waiting”)
您已经知道项目是什么。给我发消息 console.log (“waiting”)

:wink:

You can find contact informations in my profile. Use my website or my mail.

SENT - awaiting response

To be continued…