Odd ColdFusion Ajax binding error?

Brett asks:

Hope all is well, I have a CF8 issue and I was hoping that you might have a work around. I have a cfselect that is bound to another cfselect. In the second cfselect I pass two parameters to the function called in the bind. The second parameter is a comma seperated list and it is causing all kinds of errors that i am passing two many arguments to the cfc.

<cfselect name="market" id="market" class="Normal"
required="YES"
bind="cfc:COM.LocalJobs.GetMarkets({specialty},'#Form.Market#')"
display="Market"
value="Market"
bindonload="Yes"
multiple="yes">
</cfselect>

The value that is being passed back to the cfc (Form.Market) is a multiple slection from this cfselect. This is what is causing the error. Have you come acrossed anything in your journey that might help resolve this?

The first thing I did was create a simple example so I could test. I began with this file:

<cfset x = "alpha"> <cfform name="mainform"> <cfinput name="first"> </cfform> <cfdiv bind="cfc:test.stringconcat({first},'#x#')">

And then wrote my CFC method to just return the combination of the two arguments sent:

remote any function stringconcat(a,b) { return a & b; }

I ran the code to make sure it worked as is. When entering "foo" into the form field the div display fooalpha, as expected. I then edited x to be alpha,beta and immediately got:

You cannot specify more arguments to a CFC function than it declares. Error parsing bind cfc:test.stringconcat({first},'alpha,beta')

What the heck? It's clearly passing two arguments. But get this. I modified my CFC to temporarily allow for a third arg. When I did that and viewed source on the CFM, I saw this in the JavaScript:

'bindExpr':[['a','first','','value'],['b','alpha],['c',beta']]

For some reason ColdFusion assumes that I am trying to pass additional arguments. If I didn't have single quotes around them I could see that. The result would have been something like {first},alpha,beta. I tried to "trick" the compiler. I used "'alpha','beta'". I used a space between the words and the comma. Nothing worked. I finally recommended he use another delimiter. Depending on the nature of your data that may or may not be acceptable. He suggested a semicolon and I can confirm it works.

So obviously this is a bug - right? Has anyone seen this before and come up with a nicer workaround?

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support.

Lafayette, LA https://www.raymondcamden.com

Comments