Loading ...
Sorry, an error occurred while loading the content.

Re: Autocomplete return multiple results

Expand Messages
  • juliusdietz
    Hi Jenny, when I do exactly what you ve described below I get this: s.fn has no properties Any idea why? My code is: (it doesn t get as far as the alerts..
    Message 1 of 4 , Apr 2 2:17 AM
    View Source
    • 0 Attachment
      Hi Jenny,

      when I do exactly what you've described below I get this:

      "s.fn has no properties"

      Any idea why? My code is:
      (it doesn't get as far as the alerts..

      bwAutocomplete.itemSelectEvent.subscribe(myHandler);

      // define your handler
      var myHandler = function(bwAutocomplete, listItem, dataArray) {
      var title= dataArray[0];
      var summary= dataArray[1];
      alert(title);
      alert(summary);
      };

      Any help appreciated!
      Julius

      --- In ydn-javascript@yahoogroups.com, "jennykhan" <jennyhan@...> wrote:
      >
      > Hi Jim,
      >
      > You'll want to try something like this:
      >
      > // subscribe to the event and assign a handler
      > oAutoComp.itemSelectEvent.subscribe(myHandler);
      >
      > // define your handler
      > var myHandler = function(oAutoComp, listItem, dataArray) {
      > var title= dataArray[0];
      > var summary= dataArray[1];
      > document.getElementById("titlefield").value = title;
      > document.getElementById("summaryfield").value = summary;
      > };
      >
      > Hope that helps,
      > jenny
      >
      >
      > --- In ydn-javascript@yahoogroups.com, "THECREW" <jim@> wrote:
      > >
      > > Doing something wrong here, I would like to have results returned into
      > > their own form fields, instead of in the search results.
      > >
      > > Example select first record and have title in one field, summary in
      > > another. Can someone give me a hand here.
      > >
      > > <script type="text/javascript">
      > > YAHOO.example.ACJson = function(){
      > > var mylogger;
      > > var oACDS;
      > > var oAutoComp;
      > > var myServer = "results.php";
      > > var mySchema = ["ResultSet.Result", "Title", "Summary", "Url"];
      > >
      > > return {
      > > init: function() {
      > > // Logger
      > > mylogger = new YAHOO.widget.LogReader("logger");
      > >
      > > oACDS = new YAHOO.widget.DS_XHR(myServer, mySchema);
      > > oACDS.queryMatchContains = true;
      > > oACDS.autoHighlight = false;
      > > oACDS.useShadow = true;
      > > oACDS.allowBrowserAutocomplete = false;
      > > oACDS.scriptQueryAppend = "output=json"; // Needed for YWS
      > > // Instantiate AutoComplete
      > > oAutoComp = new
      > > YAHOO.widget.AutoComplete("ysearchinput","ysearchcontainer", oACDS);
      > >
      > > oAutoComp.formatResult = function(aResultItem, sQuery) {
      > > // some other piece of data defined by schema
      > > var attribute1 = aResultItem[1];
      > > // and another piece of data defined by schema
      > > var attribute2 = aResultItem[2];
      > >
      > > var aMarkup = [
      > > aResultItem[0],
      > > ": ",
      > > aResultItem[1],
      > > ": ",
      > > aResultItem[2]
      > > ];
      > > return (aMarkup.join(""));
      > > };
      > >
      > >
      > > },
      > >
      > > validateForm: function() {
      > > // Validate form inputs here
      > > return false;
      > > }
      > > };
      > > }();
      > >
      > > YAHOO.util.Event.addListener(this,"load",YAHOO.example.ACJson.init);
      > > </script>
      > >
      >
    • juliusdietz
      Hi again, I ve solved the problem so just thought in case somebody else finds this here I can point you to the solution that worked for me. Funnily from
      Message 2 of 4 , Apr 2 4:01 AM
      View Source
      • 0 Attachment
        Hi again,

        I've solved the problem so just thought in case somebody else finds
        this here I can point you to the solution that worked for me. Funnily
        from antother post by Jenny - so 'Thanks Jenny'!

        http://tech.groups.yahoo.com/group/ydn-javascript/message/10942

        I don't quite understand why it works like that though. Why can you
        pass the onItemSelect handler only tho arguments in this case and why
        does it not contain the array with the result items as a third
        parameter as described in the YUI API???

        Julius


        --- In ydn-javascript@yahoogroups.com, "juliusdietz" <juliusdietz@...>
        wrote:
        >
        > Hi Jenny,
        >
        > when I do exactly what you've described below I get this:
        >
        > "s.fn has no properties"
        >
        > Any idea why? My code is:
        > (it doesn't get as far as the alerts..
        >
        > bwAutocomplete.itemSelectEvent.subscribe(myHandler);
        >
        > // define your handler
        > var myHandler = function(bwAutocomplete, listItem, dataArray) {
        > var title= dataArray[0];
        > var summary= dataArray[1];
        > alert(title);
        > alert(summary);
        > };
        >
        > Any help appreciated!
        > Julius
        >
        > --- In ydn-javascript@yahoogroups.com, "jennykhan" <jennyhan@> wrote:
        > >
        > > Hi Jim,
        > >
        > > You'll want to try something like this:
        > >
        > > // subscribe to the event and assign a handler
        > > oAutoComp.itemSelectEvent.subscribe(myHandler);
        > >
        > > // define your handler
        > > var myHandler = function(oAutoComp, listItem, dataArray) {
        > > var title= dataArray[0];
        > > var summary= dataArray[1];
        > > document.getElementById("titlefield").value = title;
        > > document.getElementById("summaryfield").value = summary;
        > > };
        > >
        > > Hope that helps,
        > > jenny
        > >
        > >
        > > --- In ydn-javascript@yahoogroups.com, "THECREW" <jim@> wrote:
        > > >
        > > > Doing something wrong here, I would like to have results
        returned into
        > > > their own form fields, instead of in the search results.
        > > >
        > > > Example select first record and have title in one field, summary in
        > > > another. Can someone give me a hand here.
        > > >
        > > > <script type="text/javascript">
        > > > YAHOO.example.ACJson = function(){
        > > > var mylogger;
        > > > var oACDS;
        > > > var oAutoComp;
        > > > var myServer = "results.php";
        > > > var mySchema = ["ResultSet.Result", "Title", "Summary", "Url"];
        > > >
        > > > return {
        > > > init: function() {
        > > > // Logger
        > > > mylogger = new YAHOO.widget.LogReader("logger");
        > > >
        > > > oACDS = new YAHOO.widget.DS_XHR(myServer, mySchema);
        > > > oACDS.queryMatchContains = true;
        > > > oACDS.autoHighlight = false;
        > > > oACDS.useShadow = true;
        > > > oACDS.allowBrowserAutocomplete = false;
        > > > oACDS.scriptQueryAppend = "output=json"; // Needed
        for YWS
        > > > // Instantiate AutoComplete
        > > > oAutoComp = new
        > > > YAHOO.widget.AutoComplete("ysearchinput","ysearchcontainer", oACDS);
        > > >
        > > > oAutoComp.formatResult = function(aResultItem, sQuery) {
        > > > // some other piece of data defined by schema
        > > > var attribute1 = aResultItem[1];
        > > > // and another piece of data defined by schema
        > > > var attribute2 = aResultItem[2];
        > > >
        > > > var aMarkup = [
        > > > aResultItem[0],
        > > > ": ",
        > > > aResultItem[1],
        > > > ": ",
        > > > aResultItem[2]
        > > > ];
        > > > return (aMarkup.join(""));
        > > > };
        > > >
        > > >
        > > > },
        > > >
        > > > validateForm: function() {
        > > > // Validate form inputs here
        > > > return false;
        > > > }
        > > > };
        > > > }();
        > > >
        > > > YAHOO.util.Event.addListener(this,"load",YAHOO.example.ACJson.init);
        > > > </script>
        > > >
        > >
        >
      Your message has been successfully submitted and would be delivered to recipients shortly.