Skip to main content
Known Participant
September 29, 2014
Answered

Problem with cfinput autosuggest and cfcomponent

  • September 29, 2014
  • 1 reply
  • 2614 views

I am new to using cfcomponent and autosuggest.  I followed the sample given in the Adobe Help Adobe ColdFusion 9 * Using Ajax User Interface Components and Features

However, I am not getting the autosuggest to work at all.  This is what I did:

1. I created a Suggestcfc.cfc under a subdirectory called "components"

The Suggestcfc.cfc is as follows:

<cfcomponent output="false">

    <cffunction name="getProduct" access="remote" returntype="array" output="false"> 

        <cfargument name="suggestvalue" required="true">

        <cfset var myarray = ArrayNew(1)>

    <cfquery datasource="mydatabase"  name="getlist">

    SELECT DISTINCT productname FROM products

        WHERE productname LIKE <cfqueryparam value="#suggestvalue#%" cfsqltype="cf_sql_varchar">

        </cfquery>

        <cfloop query="getlist">

            <cfset arrayAppend(myarray, productname)>

        </cfloop>

        <cfreturn myarray>

    </cffunction>

   

    <cffunction name="init" output="false">

        <cfreturn this>

    </cffunction>

</cfcomponent>

2. I have a test.cfm as:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

</head>

<body>

<cfset suggest = createObject("component", "components.Suggestcfc").init()>

<cfform>

<cfinput type="text" autosuggest="suggest.getProducts({cfautosuggestvalue})" name="string">

</cfform>

</body>

</html>

So when I run the test.cfm it only showed a box and when I started typing, nothing is being suggested (retrieve from the products table).  What am I doing wrong here?  Any help is appreciated.  Thanks in advance.

This topic has been closed for replies.
Correct answer Carl Von Stetten

jackhuang,

If you are a new user, I'd suggest you not go down the <CFFORM> and <CFINPUT> path.  It is fraught with peril!  All of the ColdFusion UI stuff (including <CFFORM> and <CFINPUT>) are built on outdated javascript libraries and do not implement all of the capabilities of those libraries.


Rather, I suggest you learn a community-supported JavaScript library such as jQuery.  It provides fantastic AJAX support and has all the UI features you need, either as part of the core library, the related jQuery UI library, or the myriad of free plug-ins written by 3rd parties.  There are other libraries that offer similar functionality too: ExtJS (the CF UI stuff is mostly based on a really old version of ExtJS), Dojo, and several others.

Many experienced developers have consciously moved away from using the built-in ColdFusion UI features due to compatibility issues and functional limitations.  Thus, you will be much less likely to get useful assistance with problems you encounter using those features.  On the other hand, the community-supported JavaScript libraries have a huge user base (both within and outside the ColdFusion community), and you will undoubtedly be able to get assistance with issues you may encounter.

All of that said, after reviewing the docs, it looks like you need to change

<cfinput type="text" autosuggest="suggest.getProducts({cfautosuggestvalue})" name="string">

to

<cfinput type="text" autosuggest="cfc:suggestcfc.getProducts({cfautosuggestvalue})" name="string">

or possibly

<cfinput type="text" autosuggest="cfc:components.suggestcfc.getProducts({cfautosuggestvalue})" name="string">

Good luck,

-Carl

1 reply

Carl Von Stetten
Carl Von StettenCorrect answer
Legend
September 29, 2014

jackhuang,

If you are a new user, I'd suggest you not go down the <CFFORM> and <CFINPUT> path.  It is fraught with peril!  All of the ColdFusion UI stuff (including <CFFORM> and <CFINPUT>) are built on outdated javascript libraries and do not implement all of the capabilities of those libraries.


Rather, I suggest you learn a community-supported JavaScript library such as jQuery.  It provides fantastic AJAX support and has all the UI features you need, either as part of the core library, the related jQuery UI library, or the myriad of free plug-ins written by 3rd parties.  There are other libraries that offer similar functionality too: ExtJS (the CF UI stuff is mostly based on a really old version of ExtJS), Dojo, and several others.

Many experienced developers have consciously moved away from using the built-in ColdFusion UI features due to compatibility issues and functional limitations.  Thus, you will be much less likely to get useful assistance with problems you encounter using those features.  On the other hand, the community-supported JavaScript libraries have a huge user base (both within and outside the ColdFusion community), and you will undoubtedly be able to get assistance with issues you may encounter.

All of that said, after reviewing the docs, it looks like you need to change

<cfinput type="text" autosuggest="suggest.getProducts({cfautosuggestvalue})" name="string">

to

<cfinput type="text" autosuggest="cfc:suggestcfc.getProducts({cfautosuggestvalue})" name="string">

or possibly

<cfinput type="text" autosuggest="cfc:components.suggestcfc.getProducts({cfautosuggestvalue})" name="string">

Good luck,

-Carl

jackhuangAuthor
Known Participant
September 29, 2014

Thank you Carl.  The second one worked!  Now I have to figure out how to change the ugly blue color hovering over the list....

I found that the list is pretty slow.  I also check the jQuery http://jqueryui.com/autocomplete/#remote  but found it extremely slow also.  Maybe it's the site. On top of that I do not know I can implement the above using code given there.

I was looking at the twitter typahead at typeahead.js – examples  which look very promising and fast.  But again I don't know how to implement it together with the Coldfusion function that I have created above.