2 Replies Latest reply: Oct 30, 2009 1:02 PM by Arnout Kazemier RSS

    Autosuggest and dataset notifications / callbacks

    Phil_W Community Member

      Hi,

       

      Arnout thanks for your answer on using Javascript arrays with auto suggest.  Spot on in terms of what I needed to do in temrs of Spry datasets and I've got that part up and running now.

       

      The next question follows on from that.

       

      When a user clicks on an auto suggest from the Spry dataset thus generated it fills in the input text field as expected.  Does it do anything special with the Spry dataset such as setting the current row id / number and / or trigger any notifiers?  What I'd essentially like to do is have something that detects when a user has chosen a suggestion from auto suggest list and then pull the values from another column of the dataset / array for the same row id / number and feed that into another javascript function I have written. Possibly a notifier / callback setup ?

       

      Thanks

       

      Phil

        • 1. Re: Autosuggest and dataset notifications / callbacks
          Phil_W Community Member

          Hi,

           

          I've determined a solution to this.

           

          I added an event listener to the autosuggest element. It detects the click and calls the setrow function of SpryData on my dataset.

           

          cheers

           

          Phil

          • 2. Re: Autosuggest and dataset notifications / callbacks
            Arnout Kazemier Community Member

            Seems like I completely missed your question here. I once required the same kind of functionality inside my autosuggest. I extended the autosuggest to do a fire my callback function. This is a more secure solution that adding a click handler.

             

            Extend the following method:

             

            Spry.Widget.AutoSuggest.prototype.setValue = function(str)
            {
                 if (!this.textElement)
                      return;
                 this.textElement.value = str;
                 this.showSuggestions(false);
            
                 if(this.callback){
                      this.callback( str );
                 }
            };
            
            Than in your constructor you can add the option :
            callback: function( value ){ do stuff };
            If i miss these questions in the future don't hesitate to PM me