Problem with collection

I wrote a search and data selection based on a post from here
I got “the error WDE0025: The categoria collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor”

The collection is not the field name? here is the code i wrote in the dataset1 is a field called “categoria” this field must give me the ability to select between national and international contenders.

import wixData from “wix-data”;

$w.onReady(() => {
loadCategoria();
});

let lastFilterNombrerelato;
let lastFilterCategoria
let debounceTimer;
export function Irelato_keyPress_1(event, $w) {
if (debounceTimer){
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#Irelato’).value);},500);
}

export function dropdown1_change(event, $w) {
filter(lastFilterNombrerelato, $w(‘#dropdown1’).value);
}

function filter (nombrerelato, categoria){
if (lastFilterNombrerelato !== nombrerelato || lastFilterCategoria !== categoria) {
let newFilter = wixData.filter();
if (nombrerelato)
newFilter = newFilter.contains(‘nombrerelato’, nombrerelato);
if (categoria)
newFilter = newFilter.contains(‘categoria’, categoria)
$w(‘#dataset1’).setFilter(newFilter);
lastFilterNombrerelato = nombrerelato;
lastFilterCategoria = categoria;
}
}
function loadCategoria (){
wixData.query(‘categoria’)
.find()
.then(res => {
let options = [{“values”:‘’,“label”:‘todos’}];
options.push(…res.items.map(categortia => {
return {“value”: categortia.title, “label”:
categortia.title};
}));
$w(‘#dropdown1’).options = options;
});
}

Are you sure you spelled the collection name correctly (It’s case sensitive)?

Anyway, you make the loadCategoria() function simpler:

 function loadCategoria (){ 
wixData.query('categoria')
.distinct("title") 
.then((res) => { 
  let categories = res.items;
  let options = categories.map(c => {return {"label": c, "value": c}});
   $w("#dropdown1").options = options; 
})
}

Thanks again, i pasted your function but returned this error
public/pages/yb52p.js: Unexpected token (41:36)
39 | .then((res) => {
40 | let categories = res.items; >
41 | let options = categories.map(c => return {“label”: c, “value”: c});
| ^
42 | $w(“#dropdown1”).options = options;
43 | })
44 | }

Yes the dataset1 have the field categoria I respected the Case sensitive so the idea is search from the nombrerelato field and select from the categoria field in dataset1

Yup. I missed the {} parentheses. Fixed.

But you’re querying your collection directly. Not the dataset. Use your collection name .

Soory my ignorance, the collection name isn’t the field name?

No. the collection name is the name of the database (not the dataset).

mmm OK understood i will try to change to that the parameters. sorry im quite new with wix jaja
thanks again

No problem :slight_smile:

Ok fixed that error but now i don’t get the result from the search box nombrerelato and the categoria doesn’t display the options.

this is the code

import wixData from “wix-data”

$w.onReady(() => {
loadCategoria();
});

let lastFilterNombrerelato;
let lastFilterCategoria
let debounceTimer;
export function Irelato_keyPress_1(event, $w) {
if (debounceTimer){
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#Irelato’).value);},500);
}

export function dropdown1_change(event, $w) {
filter(lastFilterCategoria, $w(‘#dropdown1’).value);
}

function filter (nombrerelato, categoria){
if (lastFilterNombrerelato !== nombrerelato || lastFilterCategoria !== categoria) {
let newFilter = wixData.filter();
if (nombrerelato)
newFilter = newFilter.contains(‘nombrerelato’, nombrerelato);
if (categoria)
newFilter = newFilter.contains(‘categoria’, categoria)
$w(‘#dataset1’).setFilter(newFilter);
lastFilterNombrerelato = nombrerelato;
lastFilterCategoria = categoria;
}
}

function loadCategoria (){
wixData.query(‘ParticipantesConcurso’)
.distinct(“title”)
.then((res) => {
let categories = res.items;
let options = categories.map(c => { return {“label”: c, “value”: c}});
$w(“#dropdown1”).options = options;
})
}

Have a look at this line:

 newFilter = newFilter.contains('categoria', categoria) 

Are you sure the field key is “categoria”?

@jonatandor35 Yes the key is catergoria

@ricardorosenblatt you have unwanted characters here:

  ̶f̶i̶l̶t̶e̶r̶(̶$̶w̶(̶'̶#̶I̶r̶e̶l̶a̶t̶o̶'̶)̶.̶v̶a̶l̶u̶e̶)̶;̶}̶,̶5̶0̶0̶)̶;̶
  /̶/̶i̶n̶s̶t̶e̶a̶d̶ ̶u̶s̶e̶:̶
  f̶i̶l̶t̶e̶r̶(̶$̶w̶(̶'̶#̶I̶r̶e̶l̶a̶t̶o̶'̶)̶.̶v̶a̶l̶u̶e̶,̶ ̶5̶0̶0̶)̶;̶ ̶ 

@jonatandor35 I did but the follow export function mark with error

@ricardorosenblatt sorry. My bad, I thought 500 is a variable you’re trying to pass to filter(), but it was the milliseconds of the setTiemout() function. So go back to your original code.

Anyway, can you explain this line?

 filter(lastFilterCategoria, $w('#dropdown1').value); 

Shouldn’t the first variable here be lastFilterNombrerelato and not lastFilterCategoria ?

@jonatandor35 No the Filter is only for the Categoria that is related to #dropdown1 my problem in this code is that i can’t filter for the dropdown, only i can search the nombrerelato.
I fixed the code for some keynotes error but now the only think i need is to add the drop down filter.
this is the code i have now with out errors but not working the dropdown filtering.

import wixData from “wix-data”

$w.onReady(() => {
loadCategoria();
});

let lastFilterNombrerelato;
let lastFilterCategoria
let debounceTimer;
export function Irelato_keyPress_1(event, $w) {
if (debounceTimer){
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
filter($w(‘#Irelato’).value,lastFilterCategoria);
}

export function dropdown1_change(event, $w) {
filter(lastFilterCategoria, $w(‘#dropdown1’).value);
}

function filter (nombrerelato, categoria){
if (lastFilterNombrerelato !== nombrerelato || lastFilterCategoria !== categoria) {
let newFilter = wixData.filter();
if (nombrerelato)
newFilter = newFilter.contains(‘nombreDelRelato’, nombrerelato);
if (categoria)
newFilter = newFilter.contains(‘categoria’, categoria)
$w(‘#dataset1’).setFilter(newFilter);
lastFilterNombrerelato = nombrerelato;
lastFilterCategoria = categoria;
}
}

function loadCategoria (){
wixData.query(‘ParticipantesConcurso’)
.distinct(“title”)
.then((res) => {
let categories = res.items;
let options = categories.map(c => { return {“label”: c, “value”: c}});
$w(“#dropdown1”).options = options;
})
}

@ricardorosenblatt but you can’t pass a category in this way. he first variable must be nombrerelato. so if there’s no new nombrerelato, pass lastFilterNombrerelato.

@jonatandor35 OK lets go by parts, first i wrote the code for searching the nombrerelato and worked fine.
import wixData from “wix-data”;

let debounceTimer;
export function Irelato_keyPress(event, $W) {
if (debounceTimer){
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
debounceTimer = setTimeout(() => {
filter($w(‘#Irelato’).value);
},200);
}
let lastFilterNombrerelato;
function filter(Nombrerelato) {
if (lastFilterNombrerelato !== Nombrerelato) {
$w(‘#dataset1’).setFilter(wixData.filter().contains(‘nombreDelRelato’, Nombrerelato));
lastFilterNombrerelato = Nombrerelato;
}
}

After this i modified the code to try to filter of the list (even if i don’t perform a nombre relato search)
wothi the dropdown1 that have 3 options Nacional, Internacional and todos that is the default state of the list.

this is the code

import wixData from “wix-data”

$w.onReady(() => {
loadCategoria();
});

let lastFilterNombrerelato;
let lastFilterCategoria
let debounceTimer;
export function Irelato_keyPress_1(event, $w) {
if (debounceTimer){
clearTimeout(debounceTimer);
debounceTimer = undefined;
}
filter($w(‘#Irelato’).value,lastFilterNombrerelato);
}

export function dropdown1_change(event, $w) {
filter(lastFilterCategoria, $w(‘#dropdown1’).value);
}

function filter (nombrerelato, categoria){
if (lastFilterNombrerelato !== nombrerelato || lastFilterCategoria !== categoria) {
let newFilter = wixData.filter();
if (nombrerelato)
newFilter = newFilter.contains(‘nombreDelRelato’, nombrerelato);
if (categoria)
newFilter = newFilter.contains(‘categoria’, categoria)
$w(‘#dataset1’).setFilter(newFilter);
lastFilterNombrerelato = nombrerelato;
lastFilterCategoria = categoria;
}
}

function loadCategoria (){
wixData.query(‘ParticipantesConcurso’)
.find()
.then(res => {
let options = [{“value”: ‘’, “label”: ‘Todos’}];
options.push(…res.items.map(categoria => {
return {“value”: categoria.title, “label”: categoria.title};
}));
$w(‘#dropdown1’).options = options;
});

}
Running this code is not working i tried with the loadCategoria that you pass me but not working. have you any way to do a simpler selection combined with the search?