{"id":538,"date":"2012-06-05T01:24:07","date_gmt":"2012-06-04T20:24:07","guid":{"rendered":"http:\/\/www.esearing.com\/v2010\/?p=538"},"modified":"2012-06-05T01:24:07","modified_gmt":"2012-06-04T20:24:07","slug":"cfselect-bind-for-search-or-edit-on-sameform","status":"publish","type":"post","link":"https:\/\/www.esearing.com\/v2010\/2012\/06\/cfselect-bind-for-search-or-edit-on-sameform\/","title":{"rendered":"CFSelect bind for Search or Edit on same form"},"content":{"rendered":"<p>Creating a data based derived dropdown list bound to a record for Search or Edit form is sometimes needed. For search you may want to return All as your first item in the dropdown, but for edit mode you likely want to return the actual value you searched for or the actual value already existing in the database.  Imagine you are maintaining a Store list for a retail sales company and need to search\/Edit\/Copy\/Update records using one form. <\/p>\n<p>This is a solution I came up with using a CFSELECT element bound to a CFC. Note brackets have been removed.<\/p>\n<p><strong>form.cfm<\/strong><br \/>\n<code><br \/>\n\/\/set a default to return all results. get_storelist('#storenum#') is what passes ALL or a selected store number<br \/>\ncfparam name=\"storenum\" default=\"All\"<br \/>\ncfform name=myform<br \/>\nlabel for=\"storenum\" \/\/a label<br \/>\ncfselect name=\"mylist\"<strong> bind=\"CFC:get_storelist('#storenum#')\"<\/strong> bindonload=\"yes\" value=\"storenum\" display=\"storeloc\" \/cfselect<br \/>\n...<br \/>\n\/cfform<br \/>\n<\/code><\/p>\n<p><strong>CFC<\/strong><br \/>\n<code><br \/>\ncffunction name=\"get_storelist\" access=\"remote\" returntype=\"query\" hint=\"Get a list of stores\"<br \/>\ncfargument name=\"store_passed\" default=\"All\"<br \/>\n     cfset var qs = \"\"<\/p>\n<p>    cfquery datasource=\"#REQUEST.Source#\" name=\"qs\"<br \/>\n            select '#store_passed#' as storenum, ''as storeloc, 1 as sortby<br \/>\n            UNION<br \/>\n            select distinct storenum, storenum+city+state as storeloc, 2 as sortby from store_table<br \/>\n            order by sortby, storenum<br \/>\n         \/cfquery<\/p>\n<p>         cfreturn qs        <\/p>\n<p>\/cffunction<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Creating a data based derived dropdown list bound to a record for Search or Edit form is sometimes needed. For search you may want to return All as your first item in the dropdown, but for edit mode you likely &hellip; <a href=\"https:\/\/www.esearing.com\/v2010\/2012\/06\/cfselect-bind-for-search-or-edit-on-sameform\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,16,24,14],"tags":[34,35],"class_list":["post-538","post","type-post","status-publish","format-standard","hentry","category-code","category-coldfusion","category-snippets-quick-code-tips-for-single-elements-attributes-or-details","category-sql","tag-binding-data","tag-cfselect"],"_links":{"self":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/538","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/comments?post=538"}],"version-history":[{"count":2,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/538\/revisions"}],"predecessor-version":[{"id":540,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/538\/revisions\/540"}],"wp:attachment":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/media?parent=538"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/categories?post=538"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/tags?post=538"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}