Auto-Suggest Inputs
Before jumping into the deep end, let’s look at the various built-in functions that ColdFusion 8 has got to offer.
CFINPUT now includes an autosuggest feature (only available for type=”text”). This entry completion suggestions feature matches and displays the suggestion as the user types into the text input field. The user will be able to select the suggestion to complete the entry. To activate this feature, simply pass the list of suggested words (seperated by commas) into the ‘autosuggest’ parameter field.
search.cfm
<cfquery datasource=”myDB” name=”data”>
SELECT DISTINCT company_name FROM company_data
</cfquery><cfform>
Name: <cfinput type=”text” name=”company” autosuggest=”#ValueList(data.company_name)#”>
</cfform>
For the above codes, the look up for suggestions are not asynchronous. All data is retrieved during the loading of the page and hence only local data. This method is usually preferred for smaller list and information which are not required to be real time.
If you require real time information or have a long suggestion list, you may consider binding an expressions to the autosuggest field. Using ‘bind’, communications will be made to the server to retrieve live data. You may manipulate your data in the function and control your returns in anyway you please. Example as follow:
daoCompany.cfc
<cfcomponent output=”false”>
<cffunction name=”lookupName” access=”remote” returntype=”array”>
<cfargument name=”search” type=”any” required=”false” default=”">
<cfquery datasource=”myDB” name=”data”>
SELECT TOP 5 first_name FROM company_staff
WHERE UCase(first_name) LIKE Ucase(’#ARGUMENTS.search#%’)
ORDER BY artname
</cfquery>
<cfset var result=ArrayNew(1)>
<cfloop query=”data”>
<cfset ArrayAppend(result, first_name)>
</cfloop>
<cfreturn result>
</cffunction>
</cfcomponent>
search_dyn.cfm
<cfform>
Name:
<cfinput type=”text” name=”company” autosuggest=”cfc:daoCompany.lookupName({cfautosuggestvalue})”>
</cfform>

May 3rd, 2009 at 7:34 am
Amazing! Not clear for me, how offen you updating your blog.netivate.com.
Thanks
Hobosic
May 4th, 2009 at 8:28 am
Hi Hobosic,
Thanks for your comment. We are still working on the cosmetics of the site. Once we are done with it, we will try to update the blog once a week (or more if time permits :p). At the mean time, feel free to comment or discuss any topics here. We will try our best to reply them!
May 11th, 2009 at 3:48 am
Great! Thank you very much! I always wanted to write in my blog something like that. Can I take part of your post to my site? Of course, I will add backlink? Regards
May 11th, 2009 at 7:18 am
Greatings, Thanks for article. Everytime like to read you.
Zoran
May 11th, 2009 at 8:16 am
Hey Jessica!
Glad you found the information useful. Sure thing, you could use parts of my post. Your backlink is much appreciated as well!
May 13th, 2009 at 10:59 pm
That was nice. Thank you for sharing this one.
May 15th, 2009 at 2:23 am
I rarely comment on blogs but yours I had to stop and say Great Blog!!
June 13th, 2009 at 12:05 am
I really like your post. Does it copyright protected?
June 16th, 2009 at 12:58 am
hello! Nice theme on your blog
best regards, Pete