Filter database error: 'An error occurred in one of currentIndexChanged callbacks'

Hi,

I filter my database with a text input and a dropdown input (work together as AND filter) using the following code:

import wixData from “wix-data”;

$w.onReady(() => {
loadConstantsCategories();
showNextPageButtonIfNeeded();
});

let lastFilterTitle;
let lastFilterCategory;
let debounceTimerFilter;
let debounceTimerNextPage;

export function search_keyPress(event, $w) {
if (debounceTimerFilter) {
clearTimeout(debounceTimerFilter);
debounceTimerFilter = undefined;
}
debounceTimerFilter = setTimeout(() => {
filter($w(‘#searchInput’).value, lastFilterCategory);
}, 600);
}

export function category_change(event, $w) {
wixData.query(‘Cities’)
.eq(‘title’, $w(‘#dropdownCategory’).value)
.limit(1)
.find()
.then(res => {
if (res.items.length > 0) {
filter(lastFilterTitle, res.items[0]._id);
} else {
filter(lastFilterTitle, null );
}
});
}

function showNextPageButtonIfNeeded() {
// Show next page button
if ($w(‘#datasetCondos’).hasNextPage()) {
$w(‘#buttonLoadMore’).enable();
$w(‘#buttonLoadMore’).show();
} else {
$w(‘#buttonLoadMore’).disable();
$w(‘#buttonLoadMore’).hide();
}
}

function filter(title, category) {
if (lastFilterTitle !== title || lastFilterCategory !== category) {
let newFilter = wixData.filter();
if (title) {
newFilter = newFilter.contains(‘title’, title);
}
if (category) {
newFilter = newFilter.contains(‘city’, category);
}
$w(‘#datasetCondos’).setFilter(newFilter)
.then(() => {
// Show ‘Nothing found’ text if needed
let count = $w(“#datasetCondos”).getTotalCount();
count === 0 ? $w(‘#textNothingFound’).show() : $w(‘#textNothingFound’).hide();
showNextPageButtonIfNeeded();
lastFilterTitle = title;
lastFilterCategory = category;
});
}
}

function loadConstantsCategories() {
wixData.query(‘Condos’)
.include(‘city’)
.find()
.then(res => {
let categories = new Set();
res.items.map(item => {
return categories.add(item.city.title)
});
let options = [{“value”: ‘’, “label”: ‘All’}];
Array. from (categories).map(category => {
return options.push({“value”: category, “label”: category})
});
$w(‘#dropdownCategory’).options = options.sort();
});
}

If the dataset doesn’t contain the text from the text input, I get the error ‘An error occurred in one of currentIndexChanged callbacks DatasetError: could not resolve dynamic filter’ in the console, however everything works.

Thank you.

Please post the editor URL of your site. Only authorized Wix personnel can get access to your site in the editor. Please include the name of the page involved.

Thank you for your quick reply. Please find the link below: https://editor.wix.com/html/editor/web/renderer/edit/b16f1a9b-33a5-46eb-9c45-5dc24dae8ddd?metaSiteId=4d34231f-07af-4da0-8bd7-e5a87ac998fd&editorSessionId=30f06b7f-3f5b-40e7-9006-9a3677d13f2e&referralInfo=dashboard

@alexeychekanov What page?

@yisrael-wix Oops. I was sure, that this is the link to the page. The page is ‘Condos (All)’. The code is slightly different now as I continue the development. But the error in the console is the same — if you input something in the text input field that doesn’t exist, I get this error. Thank you!

@yisrael-wix , have you had a chance to take a look at this ‘Condos (All)’ page, regarding the message ‘An error occurred in one of currentIndexChanged callbacks DatasetError: could not resolve dynamic filter’ if nothing is found? Thank you in advance.

@yisrael-wix , I understood the nature of this error, however I don’t know how to solve it. The point is I have another dataset “Amenities”, which includes current item from the “Condos” dataset in its filter, set with the editor. When I programmatically filter the ‘Condos’ dataset and nothing can be found, the second dataset “Amenities” produces this error: ‘An error occurred in one of currentIndexChanged callbacks’. Thank you in advance for your help.

@alexeychekanov Well, I played with this for a while and I have to admit that I’m stumped. The system thinks it’s an error, but in fact it’s just “something that happened”. You have the amenities dataset filter based on an item that doesn’t exist if the search returns no items.

If it works, just go with it for now. Or, you could write your own onItemReady() or f orEachItem() function and disconnect the amenities dataset from the the amenities in the Repeater.

I’ll send this to QA for evaluation.

1 Like

@yisrael-wix , thank you!

@alexeychekanov I just got the answer on this…

The error message is scarier than it should be - all bark and no bite. Things are working as they should, and development will hopefully change this to a message and not an error.

Thanks!

1 Like

@yisrael-wix Thank you for your time!

1 Like

@yisrael-wix This error is still happening. And try/catch is no avail.

This is a big problem for any professional application, because the program responds normally going in the “.then” instead of going into the catch, so it means that there is no way that I can figure out there was an error in code and no way to give a meaningful message to the user or adapt the page layout to show there are no results for this filtering.

It’s been a year of this post, clearly it wasn’t fixed yet, are there any plans to correct it in the future?

I would love to give a better answer to my clients

Thank you in advance.

1 Like