HighDots Forums  

Re: Autocomplete - finding out (on blur) if the user haspicked an item from the list or not

jQuery jQuery is a fast, concise, JavaScript Library that simplifies how you traverse HTML documents, handle events, perform animations, and add Ajax interactions to your web pages. jQuery is designed to change the way that you write JavaScript.


Discuss Re: Autocomplete - finding out (on blur) if the user haspicked an item from the list or not in the jQuery forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Tom Worster
 
Posts: n/a

Default Re: Autocomplete - finding out (on blur) if the user haspicked an item from the list or not - 07-03-2009 , 03:47 PM






On 7/2/09 5:49 AM, "gnjunge" <gjunge (AT) gmail (DOT) com> wrote:

Quote:
Concerning Jörn Zaefferer autocomplete.

In many cases the autocomplete list is being filled with Key Value
pairs, such as a list of FooBars with their name and id. Using the
result function one would get the id, and drop it into a hidden field.

I want to allow users to either pick an existing FooBars from the
list, or enter a new one if he cannot find a suitable one. But for
that to work I need to know that the autocomplete box contains a
custom item, with other words: an item that was not in the list.

The result event is only triggered whenever an item was picked from
the list.

How would I go about implementing this. My starting point was to add
code to the "blur" event of the autocomplete, yet I can't get enough
information to see if the currentValue is from the list, or a custom
entry.
what i did was add a flag in the input's .data() called 'chosen'. i set the
flag in the input's .result() handler. i clear it on .change(), or on
..focus() if the input's value is an empty string.

the flag can be read whenever to determine if the value in the field is
chosen from the suggestions or typed.

Reply With Quote
  #2  
Old   
gnjunge
 
Posts: n/a

Default Re: Autocomplete - finding out (on blur) if the user haspicked an item from the list or not - 07-03-2009 , 05:39 PM






Great, thanks for the pointer , I will try that.

On Jul 3, 10:47*pm, Tom Worster <f... (AT) thefsb (DOT) org> wrote:
Quote:
On 7/2/09 5:49 AM, "gnjunge" <gju... (AT) gmail (DOT) com> wrote:



Concerning Jörn Zaefferer autocomplete.

In many cases the autocomplete list is being filled with Key Value
pairs, such as a list of FooBars with their name and id. Using the
result function one would get the id, and drop it into a hidden field.

I want to allow users to either pick an existing FooBars from the
list, or enter a new one if he cannot find a suitable one. But for
that to work I need to know that the autocomplete box contains a
custom item, with other words: an item that was not in the list.

The result event is only triggered whenever an item was picked from
the list.

How would I go about implementing this. My starting point was to add
code to the "blur" event of the autocomplete, yet I can't get enough
information to see if the currentValue is from the list, or a custom
entry.

what i did was add a flag in the input's .data() called 'chosen'. i set the
flag in the input's .result() handler. i clear it on .change(), or on
.focus() if the input's value is an empty string.

the flag can be read whenever to determine if the value in the field is
chosen from the suggestions or typed.

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.