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

Feature Request: Display all items if query is empty #38

Closed
taybin opened this issue Jun 25, 2015 · 15 comments
Closed

Feature Request: Display all items if query is empty #38

taybin opened this issue Jun 25, 2015 · 15 comments
Assignees
Milestone

Comments

@taybin
Copy link

taybin commented Jun 25, 2015

When the query is empty, I'd like to display the full set of items.

@taybin taybin changed the title Display all items if query is empty Feature Request: Display all items if query is empty Jun 25, 2015
@guylabs
Copy link
Owner

guylabs commented Jun 25, 2015

Hi Taybin,

you need to implement the proper itemsMethod which returns all items when the passed in query is empty. You can read more about the itemsMethod here: https://github.com/guylabs/ion-autocomplete#the-items-method.

Or do you mean that the component does a call to the itemsMethod with the empty query when the dialog opens such that you already have a list before entering something? This way you also need to implement what I wrote in the first paragraph, but the behavior is different when the dialog opens.

Please let me know what exactly you mean.

Thanks and regards,

Guy

@guylabs guylabs added this to the 0.2.3 milestone Jun 25, 2015
@guylabs guylabs self-assigned this Jun 25, 2015
@taybin
Copy link
Author

taybin commented Jun 25, 2015

I have a working itemsMethod function.

According to this (https://github.com/guylabs/ion-autocomplete/blob/master/src/ion-autocomplete.js#L172), it short-circuits the searchQuery $watch handler if the query is empty. I don't see any way to get the component to call the itemsMethod handler with an empty query.

@joelbrewer
Copy link

I am also trying to accomplish this. Is it currently possible?

@guylabs
Copy link
Owner

guylabs commented Jun 30, 2015

I tried to change the behavior but there are some failing tests which I need to fix. I hope I can finish it till the weekend.

@joelbrewer
Copy link

@guylabs fantastic!

@guylabs
Copy link
Owner

guylabs commented Jun 30, 2015

Hi you two,

I just added the functionality to the master. Could you please check it if it works and then write me such that I can close the issue?

Thanks and regards,

Guy

@joelbrewer
Copy link

This is really close.. Only problem is when I first open the dialog the formatting is off:
screen shot 2015-06-30 at 6 04 00 pm

@joelbrewer
Copy link

Also, it would be nice if that list remained populated after clicking on an item. But maybe that's already a feature?

@taybin
Copy link
Author

taybin commented Jul 1, 2015

I had the formatting problem too. I fixed it locally by breaking out the function $watch('searchQuery') calls into its own named function and then calling that at the bottom of the onclick handler.

@guylabs
Copy link
Owner

guylabs commented Jul 1, 2015

Ok I just fixed this issue too with the workaround that @taybin mentioned. Thanks for that!

@JahBrewski What do you mean that this list remains populated? That the list is never cleared if the query is an empty string? You mean to remove this part here right: https://github.com/guylabs/ion-autocomplete/blob/master/src/ion-autocomplete.js#L167 ?

@TimoSolo
Copy link

TimoSolo commented Jul 1, 2015

Wonderful! I was just looking for this and saw you already updated the code :)
Works well. One little issue is that it calls the method twice (once when it loads the page and again when you click on the autocomplete field)

guylabs pushed a commit that referenced this issue Jul 1, 2015
@guylabs
Copy link
Owner

guylabs commented Jul 1, 2015

Hi Timothy,

well the problem is that Angular calls the &watch method at the beginning and with this change now to allow empty values it's not possible to just call the method when the real search input field is used. If anyone has an idea how to solve this then please tell me such that I can fix it or create a pull request.

Now for this issue: @taybin @JahBrewski I closed the issue now as @TimoSolo tested it but if there is an issue just reopen it.

Thanks and regards,

Guy

@guylabs guylabs closed this as completed Jul 1, 2015
@guylabs
Copy link
Owner

guylabs commented Jul 2, 2015

Hi,

I just found out a way to not call the items-method for nothing: 5f9c56b. This also fixes some other places where the items-method was called because I set the searchQuery to an empty string.

Now the items-method is just called if the component needs the data. This also improves the performance such that it doesn't make useless calls to the back end.

Regards,

Guy

@TimoSolo
Copy link

TimoSolo commented Jul 2, 2015

Hmm.. that seems to break the initial list though.

I've got the code to work the way I want it: when you click on the ion-search it shows the full list. also when you select something it saves the search.

Created pull request: #42

@TimoSolo
Copy link

TimoSolo commented Jul 3, 2015

This still isn't working for me with the updates - it only shows the list if you start typing.. what do you think of the suggested pull request?

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

No branches or pull requests

4 participants