let remoteSearchData = {
items : [
{
id : " Banana " ,
text : " Banana " ,
label : " Fruit "
},
{
id : " Apple " ,
text : " Apple " ,
label : " Fruit "
},
{
id : " Orange " ,
text : " Orange " ,
label : " Fruit "
},
{
id : " Blackberry " ,
text : " Blackberry " ,
label : " Fruit "
},
{
id : " Coconut " ,
text : " Coconut " ,
label : " Fruit "
},
{
id : " Papaya " ,
text : " Papaya " ,
label : " Fruit "
},
{
id : " Mango " ,
text : " Mango " ,
label : " Fruit "
},
{
id : " Grapes " ,
text : " Grapes " ,
label : " Fruit "
},
{
id : " Cherry " ,
text : " Cherry " ,
label : " Fruit "
}, {
id : " Guava " ,
text : " Guava " ,
label : " Fruit "
},
{
id : " Lime " ,
text : " Lime " ,
label : " Fruit "
},
{
id : " Pepper " ,
text : " Pepper " ,
label : " Vegetable "
},
{
id : " Garlic " ,
text : " Garlic " ,
label : " Vegetable "
},
{
id : " Eggplant " ,
text : " Eggplant " ,
label : " Vegetable "
},
{
id : " Fennel " ,
text : " Fennel " ,
label : " Vegetable "
},
{
id : " Corn " ,
text : " Corn " ,
label : " Vegetable "
}, {
id : " Cucumber " ,
text : " Cucumber " ,
label : " Vegetable "
},
{
id : " Carrot " ,
text : " Carrot " ,
label : " Vegetable "
},
{
id : " Chili " ,
text : " Chili " ,
label : " Vegetable "
}, {
id : " Potato " ,
text : " Potato " ,
label : " Vegetable "
},
{
id : " Squash " ,
text : " Squash " ,
label : " Vegetable "
},
]
}
function callRemoteData ( filter , selectedOptgroup ) {
return new Promise ( function ( resolve , reject ) {
console . log ( " Remote function got called for data (so you see the functionality of the `delayInput` option) " );
let toRet = structuredClone ( remoteSearchData );
let ret = toRet . items . filter ( data => {
if ( selectedOptgroup ) {
return data . label === selectedOptgroup && data . text . toLowerCase (). indexOf ( filter . toLowerCase ()) > - 1 ;
} else {
return data . text . toLowerCase (). indexOf ( filter . toLowerCase ()) > - 1 ;
}
});
setTimeout (() => resolve ( ret ), 3000 );
//resolve(ret);
});
}
function callRemoteOptionGroups () {
// you can put a FETCH/AJAX call here
return new Promise ( function ( resolve , reject ) {
let arr = [ " Fruit " , " Vegetable " ];
setTimeout (() => resolve ( arr ), 6000 );
});
};
let select = new betterNiceSelect . BetterNiceSelect ( " #my-select " , { customOptiongroupLabels : ' callRemoteOptionGroups ' , customSearch : ' callRemoteData ' });