afcapel / stimulus-autocomplete

Stimulus autocomplete component
MIT License
478 stars 61 forks source link

Fetch on focus #121

Open elalemanyo opened 1 year ago

elalemanyo commented 1 year ago

This pr is trying to fix issue #110. The idea is to fetch data on focus if minLength is 0. The proposed solution in the issue was not working if the user select one suggestion doing click.

netlify[bot] commented 1 year ago

Deploy Preview for stimulus-autocomplete canceled.

Name Link
Latest commit 4588aa1a625ce54a60bcb7c79d4385f73338cf3b
Latest deploy log https://app.netlify.com/sites/stimulus-autocomplete/deploys/6356332dbec66f0008ad1051
ACPK commented 1 year ago

@elalemanyo I get a blank

because my resultsShown is based on HTML rather than the amount of actual results. If I may ask, how do you handle this. For example,

In other words, how do you handle searches where @results.present? equals false?

@results = product.search(params["q"])

The code below generates an error because autocomplete.js cannot find the box when there is an HTML response but @results.present? is false

 <% if @results %>
    <ul data-autocomplete-target="results"  class="list-none absolute z-10 mt-3 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm" id="options" role="listbox">
    </ul>
   <% end %>
elalemanyo commented 1 year ago

@elalemanyo I get a blank

because my resultsShown is based on HTML rather than the amount of actual results. If I may ask, how do you handle this. For example, In other words, how do you handle searches where @results.present? equals false?

@results = product.search(params["q"])

The code below generates an error because autocomplete.js cannot find the box when there is an HTML response but @results.present? is false

 <% if @results %>
    <ul data-autocomplete-target="results"  class="list-none absolute z-10 mt-3 max-h-60 w-full overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none sm:text-sm" id="options" role="listbox">
    </ul>
   <% end %>

I have to admit that I don't think I understand the question 😬 But the idea would be not to answer an empty result. What we do is that if the user has not yet entered any text what the search api responds is a few random suggestions. Anyway, this is more of an implementation issue and has little to do with functionality, IMO. Let me know if I can help you 🙂.

elalemanyo commented 1 year ago

@afcapel Is there any possibility to merge this? We have been using it for some time now and we think it works very well 🙂 Thanks

arrowcircle commented 10 months ago

Any updates on merging this?