Skip to main content
Participant
June 11, 2009
Question

bound autosuggest only displays selective results?

  • June 11, 2009
  • 1 reply
  • 1508 views

I've been stumped by this issue and hope someone here can point me in the right direction:

I have a autosuggest field that is bound to a component. When I call the component directly, it works as intended... when I try and use the component through the binding, it doesn't give me the same results.

Here's the autosuggest code:

<cfform name="teamsform">

Search for a team: <br>

Use team name, team id or any part of a team member's name.<br>

<cfinput autosuggest="cfc:/ofcomponents.teams.getteams({cfautosuggestvalue})" autosuggestminlength="2" type="text" name="userSearchTerm" size="50" typeahead="yes"><br>

<input type="submit" value="Go">

</cfform>

Here's the CFC:

<cfcomponent>

    <cffunction name="getTeams" access="remote" returntype="string">

   

            <cfargument name="usersearchterm" required="yes" type="string">

                <cfquery name="getTeams" datasource="#REQUEST.dsn#">

                SELECT t.team_name as name

                FROM of_users u left outer join of_teams t on u.of_user_id = t.user_id

                WHERE 0 = 0

                <cfif arguments.usersearchterm neq "">

                and (t.team_name like '%#arguments.usersearchterm#%'

                or t.team_id like  '%#arguments.usersearchterm#%')

                </cfif>

                and u.user_type_id in (select user_type_id from of_user_types where user_type_description = 'team')

                UNION

                SELECT t.team_name as name

                FROM of_users u, of_teams t, of_team_participants tp

                WHERE u.of_user_id = tp.participant_id and t.of_team_id = tp.team_id

                <cfif arguments.usersearchterm neq "">

                and u.first_name like  '%#arguments.usersearchterm#%'

                or u.last_name like  '%#arguments.usersearchterm#%'

                </cfif>

                and u.user_type_id = (select user_type_id from of_user_types where user_type_description = 'participant')

                </cfquery>

                   <!---  <cfdump var="#getteams#">

                    <cfabort> --->

<cfset returnlist = valuelist(getTeams.name)>

    <cfreturn returnlist>

</cffunction>

</cfcomponent>

As mentioned, when I call the component directly, like this:

<cfinvoke component="/ofComponents.teams" method="getTeams" returnvariable="varret">

   <cfinvokeargument name="usersearchterm" value="Logan">

   </cfinvoke>

   <cfdump var="#varret#">

It gives me the correct results (i.e. the Team name)

When I type the same term in the text field, I get no results. When I type in a team name, I only get a result when the team name starts with the search term I am typing. Any other search returns no results.

Can anyone see if I am doing something wrong or is there something else going on that I am not aware of?

Thanks!

    This topic has been closed for replies.

    1 reply

    BKBK
    Community Expert
    Community Expert
    July 28, 2009
    When I type the same term in the text field, I get no results. When I type in a team name, I only get a result when the team name starts with the search term I am typing. Any other search returns no results.

    That's pretty much what I expect to happen with autosuggest. You've set autosuggestminlength to 2, so Coldfusion will respond only after you type the second character. It will then show you  elements from the list -- if there are any -- whose first 2 characters match what you typed. If you want instant matching you should set autosuggestminlength to 1.