Multiple mxAjax autocomplete controls

People often want more than one autocomplete control on their page. If you examine the autocomplete example:

function init() {
 new mxAjax.Autocomplete({
   indicator: "indicator",
   minimumCharacters: "1",
   target: "statecode",
   className: "autocomplete",
   paramArgs: new mxAjax.Param(url,{cffunction:"getStateList

"}),
   parser: new mxAjax.CFQueryToJSKeyValueParser(),
   source: "searchCharacter"
 });
}

you will see that the source and destination can be set to whatever you want. So you can just write two blocks

new mxAjax.Autocomplete({
   indicator: "indicator",
   minimumCharacters: "1",
   target: "CONTROL1",
   className: "autocomplete",
   paramArgs: new mxAjax.Param(url,{cffunction:"SOMEMETHOD1"}),
   parser: new mxAjax.CFQueryToJSKeyValueParser(),
   source: "CONTROL1"
 });

new mxAjax.Autocomplete({
   indicator: "indicator",
   minimumCharacters: "1",
   target: "CONTROL2",
   className: "autocomplete",
   paramArgs: new mxAjax.Param(url,{cffunction:"SOMEMETHOD2"}),
   parser: new mxAjax.CFQueryToJSKeyValueParser(),
   source: "CONTROL2"
 });

I've shown two method names in the CFC to be called, as the argument needs to be named the same as the search source control, but this isn't a big problem as both of these can in turn call the real method that does the search (so they are just very simple wrapper methods to allow the search to work). Alternatively you could use two optional arguments named after the controls, in a single component.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
chris's Gravatar Can you tell me how to go about sending two source variables via the mxAutocomplete?

I've got a dropdown located just before the text field that I'd like users to be able to use to filter the returned results.

Right now I'm looking at setting a session variable when the dropdown changes.

Thanks
# Posted By chris | 5/25/07 2:19 PM
James Holmes's Gravatar Actually I think your session variable solution may be the simplest. This can be done via Ajax too, so it will appear seamless to the user.
# Posted By James Holmes | 6/2/07 6:16 AM
Neo's Gravatar What if I wanted multiple target fields to be returned as opposed to just 1
for the autocomplete, can that be done?
# Posted By Neo | 6/13/07 4:33 AM
James Holmes's Gravatar Returning into multiple fields may require a little custom coding with the mxData tag instead. You could return a query and populate the relevant fields with the appropriate column in the query.
# Posted By James Holmes | 6/13/07 4:40 AM
chris's Gravatar Thanks for the response regarding the use of two variables. I'm currently using the session variable solution and it works just fine.
# Posted By chris | 6/18/07 12:45 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1.