ember-power-select
ember-power-select copied to clipboard
How to retrieve `resultsCount` on every keyDown
I have an ask to display the number of results as soon as the user types something. So, I tried pulling the power select's public API object on every onkeydown.
But it seems like the event onkeydown is called before https://github.com/cibernox/ember-power-select/blob/master/addon/components/power-select.js#L606 this called. So, it's one step behind every time I try to grab the resultsCount property.
I tried a bunch of things, like setting the object as a internal property of the component, and using run.api's later() after some duration (sort of waiting for it to update itself), but no luck. Guess I'm setting it earlier and not resetting it once the power-select's updateState is called. Is there a way to grab the public object once the power-select sets its own state?
I could use the searchTerm on every onkeydown and run it through the matcher function myself manually and get a count, but that just doesn't sound right and I'm copying the same code being executed by power-select.
Is there any other way to get an updated resultsCount on every keystroke?
Thanks!
@cibernox Can you please give this a look...Might be a quick solution out there.
@neeleshsaxena do you need access to number of matches from outside the select component or only from inside?
From the outside you could use registerAPI to get notified every time of any state changes in the component. The object returned from that component contains, among other things, the current results.
I require access to it from outside the select component. I need to pass that count to an external component.
@neeleshsaxena I updated my comment. In case you saw the previous version
Oh wow. Knew I was missing something. Thank you! Just need to find out how to use this registerAPI and where is it..
@neeleshsaxena oh, I though I had documented that action but I can see now that I didn't. It has been there for ages. I have to update https://ember-power-select.com/docs/api-reference with that.
Tl;dr: It's an action that you can pass to the select like onopen or any other action.