Skip to main content

Search and Top Navigation

#9414 closed feature (wontfix)

Opened July 08, 2013 04:48PM UTC

Closed July 08, 2013 05:44PM UTC

Autocomplete: return the search term in response event?

Reported by: ronmichael Owned by: ronmichael
Priority: minor Milestone: none
Component: ui.autocomplete Version: 1.10.3
Keywords: Cc:
Blocked by: Blocking:
Description

I'd like to see the response event return the search term. My reasoning for this is that the search term is not always what is in the input box that autocomplete is bound to; the search may have been triggered programmatically with the search method. The text in the input box may also have changed since this response was requested. So I'd like to pass the actual search term which I need to do a few things with during the response event.

In one particular case I want this because I have created a dropdown-like button that when clicked triggers a special search for "recommended" results by searching for an empty string. The server returns the appropriate recommended results but I want the response event to be able to figure out that it got a "recommended" response and provide some feedback to the user.

Theoretically I suppose I could set a flag somewhere when a recommended search is kicked off by the dropdown-like button and use that later to know that it was triggered; but I'd also have to worry about clearing that if the user starts typing to search. This just seems cleaner and the "right" thing to do; the event should tell me what prompted it.

BTW I've already submitted a pull request for this with the necessary minmal changes. https://github.com/jquery/jquery-ui/pull/1025 Sorry if I should have posted about it first. This is my first pull request and I read in a few places that posting about it first was requested but then in other places it sounded like it wasn't necessary for something small. I wasn't sure if this was worth discussing.

Attachments (0)
Change History (3)

Changed July 08, 2013 04:59PM UTC by scottgonzalez comment:1

owner: → ronmichael
status: newpending

It sounds to me like you want a custom source. Can you elaborate on why you would use the response event instead of the source option? Also, since you're building a custom widget on top of autocomplete, it seems like this logic can be fully contained in the new widget that generates the button.

Changed July 08, 2013 05:23PM UTC by ronmichael comment:2

status: pendingnew

Replying to [comment:1 scott.gonzalez]:

It sounds to me like you want a custom source. Can you elaborate on why you would use the response event instead of the source option? Also, since you're building a custom widget on top of autocomplete, it seems like this logic can be fully contained in the new widget that generates the button.

That could be true. But I haven't used a custom source for this because I haven't needed to: in all cases I'm still just letting autocomplete do an ajax query to my server to get the results. When the user types something, autocomplete passes that text to the server. When the user clicks my button, it calls the autocomplete search method with a wildcard.

Yes, I am building a custom widget on top of autocomplete and could handle this entirely in there. But like I said, it felt like the "right" thing to do to have the event return with the condition that triggered it (the search term). But I understand it may not be worth the extra code if 95% of developers will never need it.

Changed July 08, 2013 05:44PM UTC by scottgonzalez comment:3

resolution: → wontfix
status: newclosed

Considering autocomplete was released over 3 years ago and this is the first time someone has requested this feature, I'd say this will get very little use. You should just implement it in your custom widget.