Opened 7 years ago

Closed 7 years ago

#9414 closed feature (wontfix)

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.

Change History (3)

comment:1 Changed 7 years ago by Scott González

Owner: set to 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.

comment:2 in reply to:  1 Changed 7 years ago by ronmichael

Status: pendingnew

Replying to 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.

comment:3 Changed 7 years ago by Scott González

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.

Note: See TracTickets for help on using tickets.