Interesting ColdFusion 8, Auto-Suggest issue to watch for
Thanks to Ed Tabara for pointing this out. If you type "1" in the search field at ColdFusion Bloggers, you will get a JavaScript error:
The page at http://www.coldfusionbloggers.org says:Bind failed for autosuggest search_query, bind value is not a 1D array of strings [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]
If you introspect the result from my server, you see something like this:
[10.0,123.0,"1ssblog","1smartsolution"]
Notice that the first two results were numbers, not strings. I tried to 'fool' JSON a bit. I added "" to the number to see if that would do it and it didn't work. Interestingly enough, if you add " " to your data, serializeJSON will keep the padding on the strings, but removes it from the numbers. So even though my data was "10(space)", serializeJSON ignored it.
So it looks like 2 possible bugs. The client side code should allow for any simple value in the array - numbers, strings, or dates. And it looks like maybe serializeJSON is a bit overzealous in converting values. I can understand converting 10 to 10.0, but "10(space)" should be left alone, especially if "Ray(space)" is left alone.
Comments
["test","camden","getter","robot chicken","william ukoh","william","coldfusion rocks","a","andrea","chad"]
Thanks for pointing it out.
Do you know if this problem was ever resolved? I have just implemented autosuggest and am getting the "bind failed for autosuggest" error when I type a number into the autosuggest box.
Thanks.
In your CFC method, return an extra alphabetical list element that will never match any data in the first character of data--I decided to use "$" but you could use any character. For example: <cfreturn "$," & ValueList(someQuery.SOME_COLUMN)> The "$" never matches any of my data but it causes the bind to work and problems with JSON serialization of the long number are also solved.
I spend a lot time try to fix this issue, but now I known I not the only, like Raymond said, just wait for a fix.
To continue with my project I use this Ben solution.
"Using the client-side auto-suggest control"
http://www.adobe.com/devnet/coldfusion/articles/cf...
It's the first one, and works very nice.
Good look fellows.
See you around.
Bye
Also, make sure that if you are using CFCs, do not have any end of request processing (OnRequestEnd.cfm or method in application.cfc) that might add additional characters or blank spaces to the returned data. Once I fixed that, my autosuggest fields started working.
I have the luxury of targeting only MSIE.
For integer values and SerializeJSON note that this will return an integer in JSON form:
<cfset someInt = 1 />
<cfset JavaCast("int", someInt) />
<cfset SerializeJSON(someInt) />
Otherwise values you think are integers may be treated as strings or floating points.
The cause of the error for me was the JSON text being returned in not absolutely JSON (it included header in the onRequestStart). Removing that worked! Not a Bug
