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

Kevin Benore's Gravatar It is odd. If you try every number (0-9), some error ... some pull results, and others just do nothing. For instance, 1 and 3 error but 2 does nothing. 5 on the other hand finds the result "500 error".
# Posted By Kevin Benore | 3/17/08 3:26 PM
Don's Gravatar Putting an underscore _ wont error, but it also wont show the result found, which is:

["test","camden","getter","robot chicken","william ukoh","william","coldfusion rocks","a","andrea","chad"]
# Posted By Don | 3/18/08 2:28 PM
Doron Katz's Gravatar I am just testing your flex solution to the blog engine. Might consider one myself, this looks interesting for sure
# Posted By Doron Katz | 4/7/08 6:19 PM
Rakshith's Gravatar This is a strange bug. Its now been logged as a bug in our bugtracker.

Thanks for pointing it out.
# Posted By Rakshith | 4/10/08 11:37 PM
PhilNg's Gravatar It does the exact same thing for binding values to a drop down to auto-populate. In my case, it converted my "Yes" to "true".
# Posted By PhilNg | 5/11/08 9:53 PM
Joey Vincent's Gravatar Hi Ray,

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.
# Posted By Joey Vincent | 7/30/08 4:09 PM
Raymond Camden's Gravatar I don't know. Give it a try in 8.0.1 though - that fixed a lot of bugs.
# Posted By Raymond Camden | 7/30/08 4:17 PM
oMaT's Gravatar I'm running 8.0.1 and I'm having the same issue. I'm sifting through a list of invoice IDs, restaurant food items and names and every time the item is a pure integer something insists that it be returned without quotes, making the autosuggest fail some of the time with the 1D array error. No matter how I try to cast the results, I can't get around it. Odd an annoying.
# Posted By oMaT | 8/1/08 2:30 PM
Joey Vincent's Gravatar Yeah, I don't think it's fixed. We're also running 8.0.1 and I still get the same error.
# Posted By Joey Vincent | 8/1/08 5:44 PM
Chris Amaro's Gravatar Having the same issue here as well. Simple form for retrieving ticket #'s (formatted 'mmddyyxxx' with 'xxxx' being an incremental). Any digit entered into the input field throws the "1D Array" error. Running 8.0.1.
# Posted By Chris Amaro | 9/4/08 1:25 PM
Raymond Camden's Gravatar I'm really surprised this isn't fixed in 8.0.1. Or the CHF for it. I guess I'd recommend then not using this feature at all. You could probably find a simple jQuery solution, and Spry supports autosuggest as well.
# Posted By Raymond Camden | 9/4/08 2:03 PM
Greg Koehlinger's Gravatar I was having binding problems with autosuggest as well when pulling back long numbers with leading zeros (e.g. 0001234567) and got scientific notation added by JSON serialization. I figured out a workaround that solves the binding and serialization problem for the time being.

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.
# Posted By Greg Koehlinger | 9/5/08 10:58 AM
Alirio Boquin's Gravatar Hi there,

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
# Posted By Alirio Boquin | 9/26/08 7:11 PM
Dave Burgan's Gravatar Has anyone come up with a solution for 'Bind failed for autosuggest, bind value is not a 1D array of strings'. Changing the returned results from my CFC to a string has not made a difference. It seems to only happen in Firefox.
# Posted By Dave Burgan | 10/22/08 12:01 PM
Greg Koehlinger's Gravatar See my suggestion above: <cfreturn "$," & ValueList(someQuery.SOME_COLUMN)> That worked for me.

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.
# Posted By Greg Koehlinger | 10/22/08 2:08 PM
Dave Burgan's Gravatar Thanks for the suggestion Greg, but that doesn't change the behavior for me. Still the same result. Any other ideas? Like I said, it only seems to happen in Firefox, and it's also related to the speed you type. If I type slow enough for the autocomplete to keep up, everything is cool. But if I type really fast and hit enter the error pops up.
# Posted By Dave Burgan | 10/22/08 2:30 PM
Greg Koehlinger's Gravatar I used the autosuggestBindDelay="1" parameter (1 second) in my <cfinput> tag and had fewer problems with speed of typing than if I left the parameter out (default is 0.5 seconds). Set higher if needed but anything higher than 3 would not seem useful for an autosuggest feature. The speed of your network and .cfc calls could affect performance. If the round-trip Ajax call takes 2 seconds and your autosuggestBindDelay is at the default of 0.5 seconds, I can imagine some collisions occurring as multiple Ajax requests return in 2, 4, 6, etc. seconds.

I have the luxury of targeting only MSIE.
# Posted By Greg Koehlinger | 10/22/08 3:36 PM
Eric Hayes's Gravatar I know this was posted months ago, but I thought I'd add a quick note about integers and SerializeJSON:

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.
# Posted By Eric Hayes | 12/22/08 2:48 PM
Abhi's Gravatar Bind Failed Error -

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
# Posted By Abhi | 4/9/09 9:40 AM