Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
informatikTirol opened this issue Oct 18, 2023 · 6 comments
Open

Comments

@informatikTirol
Copy link

informatikTirol commented Oct 18, 2023

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!

ionic-selectable_error.mov
@TheSakyo
Copy link

TheSakyo commented Nov 7, 2023

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🤷🏼‍♂️.

@AndreasGBS
Copy link

No, unfortunately not yet

@TheSakyo
Copy link

TheSakyo commented Nov 8, 2023

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)

@AndreasGBS
Copy link

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

@Lucasrsv1
Copy link

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.

@AndreasGBS
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants