I discovered that with the Autocompleter function in scriptaculous
doesn't provide a satisfying 'afterUpdateChoices' callback. This, in
my opinion, could be very usefull if you want to do something with the
list items that are populated in the div element you provide the
autocompleter with, for instance add mouse observers for custom
behavior on every list item. Because you need to know when the list is
updated and you can access the elements inside it, I figured I needed
a callback just after the list is populated.

Since onComplete ajax callback doesn't seem to work for me, I decided
to tweak the code a little bit so you can add a callback for
'afterUpdateChoices'. It are 2 simple lines,  really:

  updateChoices: function(choices) {
    if(!this.changed && this.hasFocus) {
      this.update.innerHTML = choices;
      Element.cleanWhitespace(this.update);
      Element.cleanWhitespace(this.update.down());

      if(this.update.firstChild && this.update.down().childNodes) {
        this.entryCount =
          this.update.down().childNodes.length;
        for (var i = 0; i < this.entryCount; i++) {
          var entry = this.getEntry(i);
          entry.autocompleteIndex = i;
          this.addObservers(entry);
        }
      } else {
        this.entryCount = 0;
      }

      this.stopIndicator();
      this.index = 0;

      if(this.entryCount==1 && this.options.autoSelect) {
        this.selectEntry();
        this.hide();
      } else {
        this.render();
      }
    }

    if(this.options.afterUpdateChoices)
        this.options.afterUpdateChoices(choices);
  },

It are the lower two lines you need to add to the updateChoices
function, and of course the option in your Autocompleter init with a
valid function.

Unless someone comes with a better way to get this kind of control, I
suggest it to be added in a next release :).

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to