• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

need help on CFcomponent

New Here ,
Mar 12, 2009 Mar 12, 2009

Copy link to clipboard

Copied

I have a CFC that use cfautosuggestvalue. here is the code

<cfcomponent output="false">
<cfset THIS.dsn="test">
<!--- Lookup used for auto suggest --->
<cffunction name="lookupArt" access="remote" returntype="array">
<cfargument name="search" type="any" required="false" default="">
<cfargument name="filters" type="any" required="false" default="">
<!--- Define variables --->
<cfset var data="">
<cfset var result=ArrayNew(1)>
<!--- Do search --->
<cfquery datasource="#THIS.dsn#" name="data">
SELECT DISTINCT(term)
FROM term_table
WHERE term LIKE '#ARGUMENTS.search#%'
AND distribution IN (#ARGUMENTS.filters#)
ORDER BY term
</cfquery>

<!--- Build result array --->
<cfloop query="data">
<cfset ArrayAppend(result, term)>
</cfloop>

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

My cfm page:
<cfform action="index.cfm" method="post">
<cfinvoke component="term" method="lookupArt" filters="#filters#" returnvariable="return_filters">
</cfinvoke>
<cfinput type="text"
name="term_name"
autosuggest="cfc:term.lookupArt({cfautosuggestvalue})" size="40" autosuggestminlength="2" />
<cfinput type="submit" name="submit_search" value="Search" />
</cfform>

the problem is that the filters variable passed over to the cfc but would not narrow the search term. I dont know how to get this to work?

Thanks.
TOPICS
Advanced techniques

Views

753

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 23, 2009 Mar 23, 2009
you can't use a comma-delimited list in a BIND attribute of an
autosuggest element (and of most other new cf tags that support BIND
param) - you need to change the list delimiters to something else, like
| (pipe), using the listchangedelims() cf function.

then in your cfc function you will specify that new delimiter in any
tag/function you use to process the passed list, or you can change the
delimiter back to , (comma)...

if, say, your #filters# var value is "one, two, three", then the
autosu...

Votes

Translate

Translate
LEGEND ,
Mar 12, 2009 Mar 12, 2009

Copy link to clipboard

Copied

try this:
autosuggest="cfc:term.lookupArt({cfautosuggestvalue}, '#filters#')"

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 19, 2009 Mar 19, 2009

Copy link to clipboard

Copied

thank you. I also has problems of passing list to cfcomponent. On the cfm page, i have a search and a couple checkbox to check where to search. So I need to pass it as a list over to the cfcomponent for sql. But it keeps on getting errors.

Thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 22, 2009 Mar 22, 2009

Copy link to clipboard

Copied

cfqueryparam's list attribute will solve your problem for you. However, since the list is coming from checkboxes, you'll have to contend with the possibility that none are selected.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

thanks. but when i pass over the list to the cfc, it didn't work. Is there anyway to show what's been pass over to cfc? I am wondering what kind string is being passed over.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

<cfdump var = "#arguments#">

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 23, 2009 Mar 23, 2009

Copy link to clipboard

Copied

you can't use a comma-delimited list in a BIND attribute of an
autosuggest element (and of most other new cf tags that support BIND
param) - you need to change the list delimiters to something else, like
| (pipe), using the listchangedelims() cf function.

then in your cfc function you will specify that new delimiter in any
tag/function you use to process the passed list, or you can change the
delimiter back to , (comma)...

if, say, your #filters# var value is "one, two, three", then the
autosuggest attribute in your <cfinput> tag should look like:

autosuggest="cfc:term.lookupArt({cfautosuggestvalue},
'#listchangedelims(filters, "|", ",")#')"

and your query in the cfc function will look like:

WHERE term LIKE <cfqueryparam cfsqltype="cf_sql_varchar"
value="#ARGUMENTS.search#%">
<cfif listlen(arguments.filters)>
AND distribution IN (<cfqueryparam list="yes" separator="|"
value="#ARGUMENTS.filters#">)
</cfif>


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 25, 2009 Mar 25, 2009

Copy link to clipboard

Copied

LATEST
thank you, the list causes problem because of the comma...problem solved.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation