hlsolutions / jquery-autosuggest

An AutoSuggest jQuery plugin.
http://hlsolutions.github.io/jquery-autosuggest/
GNU General Public License v2.0
15 stars 3 forks source link

Which callback filters before adding? #29

Open mimhof1 opened 11 years ago

mimhof1 commented 11 years ago

Greetings, I'm trying to locate the correct callback to filter a selection before allowing it to be added to the list. The basic idea is if the entered || comma-ed || tabbed || query is not a valid email ( using a regex here) then it clears the input box and prevents the add. I am about to hack beforeRequest but it seems to be fired with every keypress instead of hooking right before adding.

knalli commented 11 years ago

Hi,

that is not available currently. Min chars, max chars and double entries are prevented, but nothing further than that.

If you mean, please make a PR. It's welcome.

Have a look https://github.com/hlsolutions/jquery-autosuggest/blob/c7c9c93c800ee6449cea38d798ea64a8878fef98/src/jquery.autoSuggest.coffee#L983-998

mimhof1 commented 11 years ago

Hi Jan...I'm going to go after it then using beforeRequest in the meantime. Would you suggest that to be the best entry point? WHat I'll do is take the query and check if tab, enter, or comma was the last key, then if so, run the regex filter and if pass, return query and if not, clear and return empty. Sound feasible?

On Fri, Oct 18, 2013 at 3:25 PM, Jan Philipp notifications@github.comwrote:

Hi,

that is not available currently. Min chars, max chars and double entries are prevented, but nothing further than that.

If you mean, please make a PR. It's welcome.

Have a look https://github.com/hlsolutions/jquery-autosuggest/blob/c7c9c93c800ee6449cea38d798ea64a8878fef98/src/jquery.autoSuggest.coffee#L983-998

— Reply to this email directly or view it on GitHubhttps://github.com/hlsolutions/jquery-autosuggest/issues/29#issuecomment-26622901 .

mimhof1 commented 11 years ago

FYI, not sure if I sent that PR to the right place.

On Fri, Oct 18, 2013 at 3:55 PM, marc imhof marcimhof@gmail.com wrote:

Hi Jan...I'm going to go after it then using beforeRequest in the meantime. Would you suggest that to be the best entry point? WHat I'll do is take the query and check if tab, enter, or comma was the last key, then if so, run the regex filter and if pass, return query and if not, clear and return empty. Sound feasible?

On Fri, Oct 18, 2013 at 3:25 PM, Jan Philipp notifications@github.comwrote:

Hi,

that is not available currently. Min chars, max chars and double entries are prevented, but nothing further than that.

If you mean, please make a PR. It's welcome.

Have a look https://github.com/hlsolutions/jquery-autosuggest/blob/c7c9c93c800ee6449cea38d798ea64a8878fef98/src/jquery.autoSuggest.coffee#L983-998

— Reply to this email directly or view it on GitHubhttps://github.com/hlsolutions/jquery-autosuggest/issues/29#issuecomment-26622901 .

knalli commented 11 years ago

Hm. I don't think so.

  1. Clone/Checkout this repository (hlsolutions/hquery-autosuggets)
  2. Make a branch
  3. Put all your commits into this and make a PR by visiting this page https://github.com/hlsolutions/jquery-autosuggest/pulls
mimhof1 commented 11 years ago

Hi Jan, I was able to create a workaround using the callback afterSelectionAdd instead of beforeRequest. Basically, it takes "item", check that key I want to filter( item.email), and if it fails, forces an immediate $("input[name="test).autoSuggest('remove',item.email); Essentially, the item got added to the list, then we checked it, and because it failed, turned around and removed it. It's fast enough for what we need to do because the data in the list isn't being used until a separate function is called elsewhere. Thanks again for taking this plugin to a new level...and thanks for the quick responses. BTW I found your version after chasing down issues in the first one and saw your link to yours. Thanks for taking the time to do that.

On Fri, Oct 18, 2013 at 6:52 PM, Jan Philipp notifications@github.comwrote:

Hm. I don't think so.

  1. Clone/Checkout this repository (hlsolutions/hquery-autosuggets)
  2. Make a branch
  3. Put all your commits into this and make a PR by visiting this page https://github.com/hlsolutions/jquery-autosuggest/pulls

— Reply to this email directly or view it on GitHubhttps://github.com/hlsolutions/jquery-autosuggest/issues/29#issuecomment-26635807 .