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?
Archived Comments
You could try using urlEncodedFormat() to encode the data in the second param. You could then use traditional comma delimited lists, and only need one function call on each end of the cfc call. Not tested, YMMV.
Ray, I was able to make it work using a replace to change the delimiter to a semi-colon and then loop through the selections to retrun them to the top of the list, however since the selected parm does not work in a cfselect that uses a bind I can get the selected items to remain selected, has anyone found a work around for that issue? thanks again for all the help.
By any wild chance did you try Ben's solution?
No, I was able to get the data to the CFC with out issue by just changing the delimiter. So I did not see any reason to try that. Would that affect the issue i am having how with the selected items not reamining selected?
Don't know - but can't hurt?
@Ray, Bens solution worked fine, I encoded it in the bind statement and then decoded it in the cfc. It is much cleaner than the way i was doing it and that is good, but it is still not holding the selected values when the page submits. If anyone has a work around for this it would be greatly appriciated.
@Ben, thanks for the suggestion it worked great, left me with a new problem but worked and is very clean.
I thought this might be a case of needing jsStringFormat() around the variable X, but I just tested and got the same issue.
I suspect the problem is the validation parser isn't strong enough and isn't properly ignoring commas inside a quoted string, but is instead just counting all the commas that appear in the output.
You weren't using spry were you? I had this issue when I loaded my js libraries from application.cfc onRequestStart. Turned out that that I had a stray js libraries called in included pages and I was calling the functions more than once and the error was thrown. I took me about 3 solid days of console debugging before I saw it.