Hi, I am currently working on coding multiple search functions into my site. The first is a Text Input search bar the second is a Multi Checkbox.
They are both on my Dynamic Page featuring recipes. The recipes are in a database and displayed in a repeater. I want my search functions (search bar and multi checkbox) to search within my database and display results in the repeater format.
The code I’ve implemented into my search bar is working fine but when I’m in the preview mode … this error comes up in the Developer Console:
UserError: datasetApi ‘onReady’ operation failed Caused by DatasetError: Operation (onReady) not allowed during save
It indicates the error, I believe, is from Line 18 but when I’m in Editor mode, there is no error showing within the code. Wondering what I’m missing or needs to be fixed so this message doesn’t appear and everything runs smoothly.
Please see code below: (Line 18 indicated with ***)
import wixData from ‘wix-data’ ;
$w . onReady ( function () {
//SEARCH BUTTON TRIGGER
$w ( "#searchButton" ). onClick ( **function** () {
search ();
});
//ENTER KEY TRIGGER
$w ( "#searchbar" ). onKeyPress ( **function** () {
search ();
});
//SEARCH FUNCTION
**function** search () {
*** $w ( "#dynamicDataset" ). onReady ( **function** () {
$w ( "#dynamicDataset" ). setFilter ( wixData . filter (). contains ( 'recipeCategory' , String ( $w ( '#searchbar' ). value ))
. or ( wixData . filter (). contains ( "title" , String ( $w ( '#searchbar' ). value )))
. or ( wixData . filter (). contains ( "recipeTags" , String ( $w ( '#searchbar' ). value ))))
. then ( count )
$w ( "#clearFilter" ). show ();
})
}
//COUNT FUNCTION
**function** count () {
**let** count = $w ( "#dynamicDataset" ). getTotalCount ();
**if** ( count > 0 ) {
$w ( "#results" ). text = ` ${ count } recipes found` ;
} **else** { $w ( "#results" ). text = `No recipes found` ; }
**return** count ;
}
//SCROLL TO THE TOP WHEN PAGINATION IS CHANGED
$w ( "#pagination1" ). onClick (() => {
$w ( "#anchor1" ). scrollTo ();
});
//CLEAR FILTER
$w ( "#clearFilter" ). onClick ( **function** () {
$w ( "#searchbar" ). value = **undefined** ;
$w ( '#recipecheckbox' ). value = **undefined** ;
$w ( "#clearFilter" ). hide ();
$w ( "#dynamicDataset" ). setFilter ( wixData . filter ()). then ( count );
});
//COUNT BEFORE PAGE LOADS
$w ( "#dynamicDataset" ). onReady ( **function** () {
count ();
});
});
Thank you so much!