Link to home
Start Free TrialLog in
Avatar of talahi
talahi

asked on

Using auto suggest get error "Error invoking CFC"

Trying the following Ben Forta example(http://www.forta.com/blog/index.cfm/2007/5/31/ColdFusion-Ajax-Tutorial-1-AutoSuggest ) is successful,

<!--- Get data --->
<cfquery datasource="cfartgallery" name="data">
SELECT artname
FROM art
ORDER BY artname
</cfquery>

<!--- The form --->
<cfform>
Art:
<!--- Populate auto-suggest control --->
<cfinput type="text"
      name="artname"
      autosuggest="#ValueList(data.artname)#">
</cfform>

When I try to use the CFC example I get an "Error invoking CFC" message,

<cfcomponent
output="false">

<cfset THIS.dsn="cfartgallery">

<!--- Lookup used for auto suggest --->
<cffunction name="lookupArt" access="remote" returntype="string">
          <cfargument name="search" type="any" required="false" default="">

          <!--- Define variables --->
          <cfset var data="">

          <!--- Do search --->
          <cfquery datasource="#THIS.dsn#" name="data">
          SELECT artname
          FROM art
          WHERE UCase(artname) LIKE Ucase('#ARGUMENTS.search#%')
          ORDER BY artname
          </cfquery>

          <!--- And return it --->
          <cfreturn ValueList(data.artname)>
</cffunction>
   
</cfcomponent>
-----------------------------------------------------------
<cfform>
Art:
<cfinput type="text"
      name="artname"
      autosuggest="cfc:art.lookupArt({cfautosuggestvalue})">
</cfform>


Other queries work in this directory.
Avatar of azadisaryev
azadisaryev
Flag of Hong Kong image

iirc, a function with access="remote" cannot have optional arguments. try changing your cfargument to required="true"

as with all cf ajax features, you can add ?cfdebug to the url of your page to enable cf ajax debugger (provided it is enabled in cf admin), and see somewhat more detailed error messages.

and using firefox with firebug can help you even more.
make sure you point to the right path where your cfc are stored

Avatar of gdemaria
Your CFC should be called art.cfc and be located in the root directory.  Is that the case?  When binding, it will not find it in other locations.
Avatar of talahi
talahi

ASKER

Thanks for the responses. Here is the error I receive,

" Error invoking CFC /art.cfc : Element DS is undefined in VARIABLES. [Enable debugging by adding 'cfdebug' to your URL parameters to see more information]"

I don't believe this "Element DS is undefined in VARIABLES" since it is used in the first attempt and works fine, even when hardcoded as defined in the application.cfm file.

<cfquery datasource="#variables.ds#" name="data">
SELECT artname
FROM art
ORDER BY artname
</cfquery>

- I changed cfargument to required="true" but that didn't affect the result.

-  root directory.  Right now the art.cfc is in the same location as the cfform page calling it.  My CF book also mentions putting it in the '...\components folder but that didn't work (not sure how to change the path in the CFFORM calling it.

I also see information about using <cfinvoke intead.  Looking at that now.

Here is what I see when I look at the View Source page in Firefox.  It looks like all the ajax support files are being found.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><script type="text/javascript">_cf_loadingtexthtml="<div align='center'><img src='/CFIDE/scripts/ajax/resources/cf/images/loading.gif'/>";
_cf_contextpath="";
_cf_ajaxscriptsrc="/CFIDE/scripts/ajax";
_cf_jsonprefix='//';
</script><script type="text/javascript" src="/CFIDE/scripts/ajax/yui/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/yui/animation/animation-min.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/yui/autocomplete/autocomplete-min.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/messages/cfmessage.js"></script>

<script type="text/javascript" src="/CFIDE/scripts/ajax/package/cfajax.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/ajax/package/cfautosuggest.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="/CFIDE/scripts/ajax/resources/yui/yui.css" />
<link rel="stylesheet" type="text/css" href="/CFIDE/scripts/ajax/resources/cf/cf.css" />

<script type="text/javascript">
      ColdFusion.Ajax.importTag('CFINPUT-AUTOSUGGEST');
</script>

      <script type="text/javascript">
            var _cf_autosuggest_init_1224599433739=function()
            {
                  var _cf_autosuggestarray=[];
                  
                  var _cf_autosuggestdatasource= new YAHOO.widget.DS_JSArray( _cf_autosuggestarray);
                  var _cf_autosuggest= new YAHOO.widget.AutoComplete( 'artname','artnamecontainer',_cf_autosuggestdatasource);
                  _cf_autosuggest.onbinderror=null;
                  _cf_autosuggest.prehighlightClassName = "yui-ac-prehighlight";
                  _cf_autosuggest.typeAhead = false;
                  _cf_autosuggest.maxResultsDisplayed = 10;
                  _cf_autosuggest.useShadow = true;
                  _cf_autosuggest.showloadingicon = true;
                  _cf_autosuggest.containerCollapseEvent.subscribe(ColdFusion.Autosuggest.triggerOnChange);
                  _cf_autosuggest.id='artname'
                  _cf_autosuggest.valuePresent=false
                  _cf_autosuggest.doBeforeExpandContainer=_cf_resetLoadingIcon_1224599433740;
                  
                  YAHOO.util.Event.addListener("artname","blur",_cf_resetLoadingIcon_1224599433740);
                  ColdFusion.objectCache["artname"] = _cf_autosuggest;
                  document.getElementById("artnamecontainer").style.left = document.getElementById("artname").offsetLeft;
                  YAHOO.util.Event.addListener("artname","keyup",_cf_onKeyUp_1224599433741,_cf_autosuggest);
            };ColdFusion.Event.registerOnLoad(_cf_autosuggest_init_1224599433739);
            _cf_resetLoadingIcon_1224599433740=function()
            {
                  document.getElementById("artname_cf_button").src='/CFIDE/scripts/ajax/resources/cf/images/static.gif';
                  return true;
            };_cf_onKeyUp_1224599433741=function( arg,autosuggest)
            {
                  
                  var cfautosuggestvalue=document.getElementById('artname').value;
                  
                  if( ColdFusion.Autosuggest.checkToMakeBindCall(arg, "artname", autosuggest, cfautosuggestvalue) ){
                  ColdFusion.Bind.cfcBindHandler(null, {'bindTo':ColdFusion.Autosuggest.loadAutoSuggest,'bindToAttr':'true','cfc':'/art.cfc','cfcFunction':'lookupArt','bindExpr':[['search',cfautosuggestvalue]], 'bindToParams': { 'autosuggestid':"artname" }});
                        }
            };
            
      </script>
      <script type="text/javascript">
<!--
    _CF_checkCFForm_1 = function(_CF_this)
    {
        //reset on submit
        _CF_error_exists = false;
        _CF_error_messages = new Array();
        _CF_error_fields = new Object();
        _CF_FirstErrorField = null;


        //display error messages and return success
        if( _CF_error_exists )
        {
            if( _CF_error_messages.length > 0 )
            {
                // show alert() message
                _CF_onErrorAlert(_CF_error_messages);
                // set focus to first form error, if the field supports js focus().
                if( _CF_this[_CF_FirstErrorField].type == "text" )
                { _CF_this[_CF_FirstErrorField].focus(); }

            }
            return false;
        }else {
            return true;
        }
    }
//-->
</script>
</head>

<body>

<form name="CFForm_1" id="CFForm_1" action="/test_autosuggest.cfm" method="post" onsubmit="return _CF_checkCFForm_1(this)">
artname:

<div  id="artnameautosuggest" class="autosuggest">
      <div  style="float:left;">
            <input name="artname" id="artname"  type="text" class="autosuggestinput"  />

       </div><div  id="artnameloadingicon" style="float:left;">
            
            <img id='artname_cf_button' src="/CFIDE/scripts/ajax/resources/cf/images/static.gif"/>
       </div><div  id="artnamecontainer" class="autosuggestcontainer" style="float:left;">
            
       </div>
 </div>  
</form>
 

</body>
</html>
Avatar of talahi

ASKER

It seems to work now but not sure why.  Still looking at it.
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial