March 12, 2010

Pages


Search Site


Topics



Archives

Using Bind with CFSELECT

February 10 2009 by admin
Back in the olden days of CFML there was a script called CF_Select_Two_related. It allowed you to select from one dropdown <select > and populate the second dropdown <select > with related data from a query. 10 years ago it was really cool. But now in ColdFusion 8 you can use the bind attribute and bind to a cfc passing data to it from other cfselects. Its AJAX so no page refresh and its very cool and useful. However, there is one pit fall you must know. If you have so much as ONE comment in application dot cfm or cfc, the bind onload function will fail and the your cool dropdowns will just sit there. Hopefully there is a plan to fix that in CF 10. Here is an example from: http://blog.web-shorts.com/post/cfselect-binding-and-selectedvalues <cfselect
name="city_id"
bind="cfc:cfcs.Remote.getCities({inventoryDetails:state_id}, #MyProperty.getCity_ID()#)"
bindOnLoad="true"
value="ID"
display="CityName"
/>
Remote.cfc <cffunction name="getCities" access="remote" returntype="query" hint="Returns a query of cities for a specific state">
<cfargument name="state_id" type="numeric" required="true" />
<cfargument name="selectedValue" type="numeric" required="false" default="0" />
<cfset var rs = "" />

<cfif Val(Arguments.State_ID) IS 0>
<cfset rs = QueryNew("ID, CityName") />
<cfset QueryAddRow(rs) />
<cfset QuerySetCell(rs, "ID", 0) />
<cfset QuerySetCell(rs, "CityName", "Choose a state first...") />
<cfelse>
<cfquery name="rs" datasource="#DSN#">
SELECT
ID
, CityName
FROM (
SELECT
ID
, CityName
, CASE WHEN ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.SelectedValue#" />
THEN 0
ELSE 1
END AS Sort
FROM City (NOLOCK)
WHERE State_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#Arguments.State_ID#" />
) d
ORDER BY Sort, CityName
</cfquery>
</cfif>

<cfreturn rs />

</cffunction>

Posted in CFC Binding | 3 comments

3 responses to “Using Bind with CFSELECT”

  1. Rainey Says:

    Greeting. Keep the good works comming. Help me! Looking for sites on: Handmade norfolk soaps. I found only this - <a href="http://www.geo600.de/Members/Soap">handmade Soap cutters trimmers</a>. Essential main, first and hand-made actual and many strange arrivals were near then divided, wanting to tanning visitors. In the philippines handmade experimental products range that slaves have fifth women, and catch to prevent their blocks. Thank :confused: Rainey from Bangladesh.
  2. Algarve Villa Rentals Says:

    Well this is very interesting indeed.Would love to read a little more of this. Great post. Thanks for the heads-up…This blog was very informative and knowledgeable
  3. Mathilda Says:

    Hello. Good afternoon friends ;). Help me! Need information about: Want more celebrex keywords. I found only this - <a href="http://sit.comune.feltre.bl.it/Members/Norvasc/does-norvasc-cause-gum-problems-gingivitis">does norvasc cause gum problems gingivitis</a>. Maintain 3-5 thanks ace at an need of 2 bed, norvasc. Increased you include that a acquirable patent urine can together contain cheap nursing? THX :-), Mathilda from Colombia.

Leave a Reply