Copy link to clipboard
Copied
I have the autosuggest working with an <cfinput input field which calls a CFC function and returns the last name from a database. While this is great, it would be nice to return more information than just the last name. Is it possible to return "Last Name, First Name and Address Information" in the Autosuggest? I want my user to see that Smith[1] is different than Smith[2] and so on.
Is this possible?
Copy link to clipboard
Copied
NettlesD,
That is something which you need acheive in your query statement, In other words modify your current query to display the names the way you want.
ColdFusion's autosuggest will just display suggestions that are being returned from the query and has nothing to do with this requirement.
HTH
Copy link to clipboard
Copied
As Dave replied. One set of strings is no different then another set of strings.
Modify your CFC to return the data the way you want it.
Copy link to clipboard
Copied
Ah, so you just add that extra information you want. This is what you are talking about?
What I currently have:
<cffunction name="Lookup" access="remote" returntype="array" output="no">
<cfargument name="suggestvalue" required="true">
<cfset var Results = ArrayNew(1)>
<cfquery name="getDBNames" datasource="#application.DataSourceMDC#">
select IFirstName,
LastName
from Registrant
where lower(lastname) like <cfqueryparam value="#LCase(suggestvalue)#%" cfsqltype="cf_sql_varchar">
</cfquery>
<!--- Convert the query to an array. --->
<cfloop query="getDBNames">
<cfset arrayAppend(Results, LastName)>
</cfloop>
<cfreturn Results>
</cffunction>
What I need to do:
<cffunction name="Lookup" access="remote" returntype="array" output="no">
<cfargument name="suggestvalue" required="true">
<cfset var Results = ArrayNew(1)>
<cfquery name="getDBNames" datasource="#application.DataSourceMDC#">
select LastName||', '||FirstName as Name
from Registrant
where lower(lastname) like <cfqueryparam value="#LCase(suggestvalue)#%" cfsqltype="cf_sql_varchar">
</cfquery>
<!--- Convert the query to an array. --->
<cfloop query="getDBNames">
<cfset arrayAppend(Results, Name)>
</cfloop>
<cfreturn Results>
</cffunction>
Copy link to clipboard
Copied
Yeah.. You are spot on!..
Copy link to clipboard
Copied
Is there an easy way to just grab the LastName and place that in the field versus all the extra information? Meaning, the Autosuggest is a LastName input field but I needed "first name, address....so on" to better identify the person but I ONLY want LastName as the text in that field. Is there a way to do that?
Oh, I take it you can't create a structure within an array and return that?