Reputation: 1031
I am creating a form and for what ever reason, when using a bindOnLoad
with a remote CFC, my default value doesn't seem to appear.
Here is the cfselect:
<cfselect name="edcs"
id="edcs"
multiple="false"
bind="cfc:Components.requestSearch.getEDCs()"
bindonload="true"
value="edc_nm"
display="edc_nm">
<option name="">Select an EDC</option>
</cfselect>
And here is the function:
<cffunction name="getEDCs" access="remote" returntype="query">
<cfscript>
var queryService = new Query();
queryService.setDatasource("#APPLICATION.db2system#");
queryService.setName("getEDCs");
queryService.setUserName("#APPLICATION.db2logon#");
queryService.setPassword("#APPLICATION.db2pass#");
queryService.setSQL(
"select distinct rtrim(edc_nm) as edc_nm
from #APPLICATION.db2owner#.pms_account");
var result = queryService.execute();
var edcs = result.getResult();
return("#edcs#");
</cfscript>
</cffunction>
So, when the page loads I see the <option ...>
value displayed for a split second and then the list gets populated, and the Select an ECD
disappears. I need to have a choice for a null value, which is what the option is for. What am I doing wrong? Thanks.
Addition: According to the CF10 docs, I should be able to use the <option>
html tag.
http://help.adobe.com/en_US/ColdFusion/10.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7afe.html
Upvotes: 3
Views: 3305
Reputation: 1083
I've run across this issue with CFSELECTs and binding CFCs. I have also been unable to add an <option></option>
tag with a bound CFSELECT. The best way would be to create the query and force the result to have the desired input on the top. For example:
SELECT distinct
rtrim(edc_nm) as edc_nm_display,
rtrim(edc_nm) as edc_nm_value
FROM #APPLICATION.db2owner#.pms_account
UNION
SELECT
'Select an EDC' as edc_nm_display,
'0' as edc_nm_value
FROM dual
ORDER BY 2
This will return your query with 'Select an EDC' on the top.
Also, as a check, I believe <option name="">Select an EDC</option>
should be <option value="">Select an EDC</option>
. I hope that helps.
Upvotes: 2
Reputation: 5140
Return is not a function ...
return("#edcs#");
Try changing your function to ...
var result = queryServices().execute().getResult();
return result;
Upvotes: 1
Reputation: 4118
The query will need to return that value. Try adding it as a UNION statement.
Upvotes: 1