Opened 10 years ago
Closed 10 years ago
#8784 closed bug (wontfix)
trigger search from select within jquery ui autocomplete not working
Reported by: | bugtester | Owned by: | bugtester |
---|---|---|---|
Priority: | minor | Milestone: | 1.10.0 |
Component: | ui.autocomplete | Version: | 1.9.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
Description
Hi,
I want (in this simplify case) search a text and if I select it, its should search the search text again. I found this: http://api.jqueryui.com/autocomplete/#method-search
But thats working only outside of autocomplete: http://jsfiddle.net/uSbLC/5/
Is it possible in select method of 1.9.1?
Steps:
- go to text field and insert "a"
- now you get a popup with 2 results
- select one result, now its should appear the popup again, but nothing happen here
BUT look into firebug. After click on item you get a new response in console.
If I click on button, the popup show up. What is here my mistake? I need it in select handler. After select a entry, a new search should immediately start and show a popup.
Because its working in older versions of jquery-ui for me two year long with every update fine, I report this as an urgend bug for me.
Change History (5)
comment:1 follow-up: 2 Changed 10 years ago by
Owner: | set to bugtester |
---|---|
Status: | new → pending |
comment:2 Changed 10 years ago by
Status: | pending → new |
---|
First, this working from beginning since I use jQueryUI.. so long almost 2 years, I think. My last version was 1.8.20 before I updated to 1.9.x. Hera a jsfiddle with 1.8.20: http://jsfiddle.net/Khj79/ Here its working, but have mess with the popup. In my versions I dont had problems with popup.
Why I need it: I have a search for names. The result of this search are 10 names and a last (11.) entry for "search the next results". With click on this last entry I get the next 10 results and so on. In last popup I have "start from beginning". All other entry close the popup (click on names).
Example popup1:
- Name 1
- Name 2
- Name 3
...
- search the next results
click on "search the next results" now coming popup2:
- Name 11
- Name 12
- Name 13
...
- search the next results
click again on "search the next results" now coming popup3:
- Name 21
- Name 22
- Name 23
...
- search the next results
Here my simplify code for it thats working now 2 years. In $('#search').data('p') I save the "popup counter" and send it with ajax and get the next number with ajax-response.
$('#search').autocomplete( { source: function(request, response) { if ($('#search').data('p')=='undefined') { $('#search').data('p', 0); } $.postJSON('ajax/search', { t: request.term, p: $('#search').data('p') }, function(data) { if (data && data.s==$('#search').val()) { $('#search').data('p', data.p); response($.map(data.r, function(item) { // more code.... })); } }) }, open: function(event, ui) { // Delete stupid help text $(this).autocomplete('widget').removeClass('ui-widget-content').addClass('searchbar-popup').position( { of: $('#search'), my: 'left top', at: 'left bottom', offset:'0 3' }); }, focus: function() { return false; }, select: function(event, ui) { if (ui.item.url=='') { $(this).autocomplete('search', $(this).val()); } else { $('#search').data('p', 'x'); window.location.href = ui.item.url; } return false; }, minLength: 1, html: true }).keydown(function() { if ($('#search').data('p')!='x') { $('#search').data('p', 0); } }).keyup(function(event) { if (event.keyCode=='13' && $('#ui-active-menuitem').length==0 && $('#search').data('p')!='x') { // more code.... } }).click(function() { $('#search').data('p', 0); $(this).autocomplete('search', $(this).val()); });
The next example (without code) is to make a multi choice system:
- Search a word
- now you get all results for this word
- click on the word and can now are the final step or there is a sub category with sub searches and you see new another results for your searching.
Search "manager" Ajax-Result: chief manager, production manager, sales manager, .... click on "sales manager" .. go to sale manager site click on "product manager" .. he found that have children and open it (expand popup or exchange popup) click on sub request .. go to child entry from "product manager"
there are more options for use autocomplete. for me the first with "page counter" is the main problem. I have a live example, but not for public view. I hope this is not again a 2 years old bug like my last bugreport that now is "fixed". :(
I understand your explain, but why working this now so long. Is there a way to fix this for my self? What must be change in jquery-ui? I hope anybody can help here.
comment:3 follow-up: 4 Changed 10 years ago by
Status: | new → pending |
---|
There were some pretty big changes to autocomplete between 1.8 and 1.9, specifically selection is now synchronous where before it was asynchronous. Is there a reason you can't just use a timeout inside the select? This is certainly an edge case.
comment:4 Changed 10 years ago by
Status: | pending → new |
---|
Thanks for your fast answer.
Replying to scott.gonzalez:
Is there a reason you can't just use a timeout inside the select?
I can add a timeout, that is not a problem: http://jsfiddle.net/uSbLC/10/ and its working fine. But I have no idea which value for duration is the "best". Is it right that settimeout only starts when the function is completed. So I can always set duration to "1" for start immediately?
comment:5 Changed 10 years ago by
Resolution: | → wontfix |
---|---|
Status: | new → closed |
As I said, autocomplete selection is always synchronous, so any value inside setTimeout()
will work. Digging through the 1.8.x code, this only worked as a side effect of a work around for IE's asynchronous focus handling.
I don't really understand what you're trying to accomplish. I'm inclined to close as wontfix because I can't imagine any use cases for this.
What's happening is selecting an item always closes the menu. Closing the menu tells the autocomplete to ignore any pending searches. This includes the search that you're manually triggering immediately before the menu closes. It's also worth noting that you're running a duplicative search, since you're triggering the search before the value updates.