ionic-selectable icon indicating copy to clipboard operation
ionic-selectable copied to clipboard

Clear search does not fire onSearch and does not clear the filter

Open informatikTirol opened this issue 1 year ago • 6 comments

Hi, clear search does not fire onSearch event and does not show the complete selectable list again. I have to type character and delete it again to see to complete list, see video.

"@ionic/angular": "^7.5.0",
 "ionic-selectable": "^5.0.3",

THX!

https://github.com/eakoriakin/ionic-selectable/assets/16346085/e4916a31-0466-48e5-a147-37edaefdc08d

informatikTirol avatar Oct 18 '23 05:10 informatikTirol

Have you solved the problem, that would be very useful ?

I have the same problem, would it be possible to implement an onClearSearch function for an event when on clear search. I saw that there was already a _onSearchbarClear() function in component, but it returns void and it has no parameters🤷🏼‍♂️.

TheSakyo avatar Nov 07 '23 14:11 TheSakyo

No, unfortunately not yet

AndreasGBS avatar Nov 08 '23 05:11 AndreasGBS

If it helps, after studying the component, I found a solution. Unfortunately, I couldn't find any other way to do it, it's a "workaround", so there is a way to rewrite a function with javascript.

So I rewrote the _onSearchbarClear() function:

this.selectableComponent._onSearchbarClear = function()
{
    this._searchText = ''; // Clear Search Text
    this._filterItems(); // Reeffects a filter on the items
}

this._filterItems() is a function of the ionic-selectable component that filters items. this.selectableComponent is a ViewChild that retrieves my ionic selectable component: @ViewChild('selectableComponent') selectableComponent!: IonicSelectableComponent;.

I hope I've been able to help you solve your problem.

(it's best to write the code I sent you in the 'ngAfterViewInit()' angular lifecycle)

TheSakyo avatar Nov 08 '23 14:11 TheSakyo

@TheSakyo THX, I'll give it a try and report back

AndreasGBS avatar Nov 08 '23 15:11 AndreasGBS

I noticed this same issue today on my app, but @TheSakyo 's workaround was not working for me.

So instead I used patch-package and added the line this._filterItems(); directly in the files inside node_modules.

Until this bug is properly fixed on this repository, if anyone would like to use the same patch I made, you can download the patch file here: ionic-selectable+5.0.3.patch

In order to use it, create a folder named patches and put the patch file inside it. Then, run npm i -D patch-package and add "postinstall": "patch-package" to your package.json scripts. After that, whenever you run npm install the patch will be automatically applied to node_modules.

Lucasrsv1 avatar Dec 15 '23 01:12 Lucasrsv1

Thanks @Lucasrsv1, I'll try that too. Unfortunately, @TheSakyo's solution didn't work for me either. Hopefully this will be solved directly by the component in the medium term.

AndreasGBS avatar Dec 15 '23 06:12 AndreasGBS