Hi Colin

I studied the code a bit, and it seems its somewhat different for the Ajax.Autocompleter compared to the Local.Autocompleter.
To understand what really happens I've tried to wrap up some of the important events.

1) The ajax request will run onComplete when done, and if you look in the code, the onComplete runs "updateChoices".
2) updateChoices is part of the Base and fills the result from backend into the resultdiv adds some events and runs the "render"
3) render will either hide or show the result
4) when an item is clicked the event selectEntry is triggered, and that method runs updateElement
5) updateElement can be passed in as your own function using the option updateElement: myUpdateElement. The method will take whatevers in the listitem and either add it to a list of values in the formfield (if you use tokens) or just replace the value in the formfield with selected value. At the very end of this method it checks to see if there is an option to run "afterUpdateElement" which is a method that also can be added as an option.

It seems to me that you need to copy updateElement, make some changes to it so it can extract the ID from say a hidden SPAN within the LI (use css to hide it) and place the ID in some hidden form field. Maybe that'll work :D
Please feel free to share code using pastebin or whatever... maybe the code can be tweaked. Either way sharing is good for the soul, and will grant you a spot in open-source-heaven ;P

-Tommy

---------- Forwarded message ----------
From: "Colin Angevine" <[EMAIL PROTECTED]>
To: rails-spinoffs@lists.rubyonrails.org
Date: Mon, 14 Aug 2006 11:48:13 -0400
Subject: Re: [Rails-spinoffs] Re: Ajax.Autocompleter with a twist
Tommy,

Thanks for getting back to me so quickly. Overriding the method in
controls.js seems like an effective approach, but after looking
through the _javascript_ for almost an hour I'm having a hard time
figuring out how I should go about doing this. A few questions:

 -Which method should I be overloading? Some methods work for the
mouse functionality while others deal with the keyboard, and rather
than writing this in a few times I'm hoping to just throw in a few
lines of code in one place to manage this.

 -Where do you recommend I store the ID from the database? Should I
put it in the id of the <li> perhaps? What did you do?

With these two things nailed down, I think that it shouldn't be too
much of an issue to figure out how to get that ID number from the AJAX
response to store it in the main page.

Thanks,
Colin

_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to