1

I currently working on a ColdFusion (CF) project adding features to our employee appreciation award web app.

The problem I am having is how to keep the cfselect value when returning to the web page where it was selected.

Currently the nomination.cfm populates #1 drop down menu with the sub-departments names, and that is called from nomination.cfc cffunction getDept. Once that is selected then "department" passed to nomination.cfc cffunction getEmp as a cfargument.

1. Select the location where your nominee works: 
<cfselect name="department" bind="cfc:nominee.getDept ()" bindonload="true" />

2. Select the nominee from the list below
<cfselect name="employee" bind="cfc:nominee.getEmp ({department})" />

All this code is inside a cfform where is it submitted to summary.cfm. In summary.cfm there's an edit button that goes back to the nomination.cfm. I used

<input type="button" value="    Edit   " onclick="history.go(-1);">

But #1 and #2 did not kept its selected values, instead defaulted to the original drop down menu listing. I read in docs that cfc binding can not do "selected", so I am at a loss. Thanks in advance for your help!!

Here below is the nomination.cfc codes:

    <!--- Get array of media types --->
    <cffunction name="getDept" access="remote" returnType="array">

        <!--- Define variables --->
        <cfset var data="">
        <cfset var result=ArrayNew(2)>
        <cfset var i=0>     

        <!--- Get data --->
        <cfquery name="data" datasource="HatsOff">
        SELECT account_number, account_title
        FROM departments
        <cfif session.vdept is not "All" and session.vdept is not "Letter">
        WHERE [departmentname] = '#session.vdept#'  
        </cfif>
        ORDER BY account_title
        </cfquery>

        <!--- Convert results to array --->
        <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[i][1]=data.account_number[i]>
            <cfset result[i][2]=data.account_title[i]>
        </cfloop>

        <!--- And return it --->
        <cfreturn result>
    </cffunction>

    <!--- Get art by media type --->
    <cffunction name="getEmp" access="remote" returnType="array">
        <cfargument name="department" type="string" required="true">

        <!--- Define variables --->
        <cfset var data="">
        <cfset var result=ArrayNew(2)>
        <cfset var i=0>

        <!--- Get data --->
        <cfquery name="data" datasource="HatsOff">
        SELECT emp_id, emp_full_name
        FROM employees
        WHERE account_number = '#ARGUMENTS.department#'
        ORDER BY emp_full_name
        </cfquery>

        <!--- Convert results to array --->
        <cfloop index="i" from="1" to="#data.RecordCount#">
            <cfset result[i][1]=data.emp_id[i]>
            <cfset result[i][2]=data.emp_full_name[i]>
        </cfloop>

        <!--- And return it --->
        <cfreturn result>
    </cffunction>

</cfcomponent>
  • There is a `selected` attribute in `` and the docs say: `"This attribute applies only if selection list items are generated from a query. The cfform tag preserveData attribute can override this value."` Any luck with that? – Alex Sep 23 '15 at 17:27
  • *I read in docs that cfc binding can not do "selected"* Are you sure? Thought that feature was added sometime around CF9.0.1. Side note, your question tags include jquery. If this is a new application, and you have the option of using jQuery, I would recommend using that instead of the CF UI stuff - which is "quirky" ... at best. – Leigh Sep 23 '15 at 21:59
  • Thanks for your comments, all! Leigh, you are right that cfc binding can not do "selected". I have resorted to another method. – Edward Soong Sep 24 '15 at 02:05
  • Actually my impression was that it *is* supported in one of the later versions, 9.0.1+ (maybe ?). However, for earlier versions you do have to roll your own. If you found an alternative, do not forget to post it as an "answer" to help the next guy that runs into this question. – Leigh Sep 27 '15 at 05:50

1 Answers1

0

I have ColdFusion version 11,0,15,311399.

The 'selected' attribute works for me in cfc bind like this:

<cfselect selected="#Value#"  name="Access_Level_Code_New"
          size="1" 
          bind="cfc: APP_CFC.Example.GetAccessLevelSetRemote({Business_Area_Code_New},{System_Function_Code_New})" 
           bindonload="yes"
 >

I assume that it should work for newer ColdFusion versions also.

Community
  • 1
  • 1
Simon
  • 1