What
This patch allows an {afterUpdateElement: function() } option function to be supplied to the Autocompleter.Base() constructor.
The function hook is executed as the last line of Autocompleter.Base.updateElement() and is passed the updated element as its argument.
control_AutocompleterBaseUpdateElement.diff
Why
This hook is required to monitor the user's selection of items in the autocomplete option list. I use this hook to trigger an update of a preview div. The preview shows the user more information about the selection they've made using Ajax.Request(). I'm sure you rails guys could make good use of a hook that could pull down a live preview of some system entity? At first I used Ajax.Updater() but I've since moved to using a simple request that returns my entity summary information as a JSON string.
Example
QuickFinder.mov (H.264)
code
<script language="JavaScript">
var entityType = 'Supplier';
function loadResult(element)
{
new Ajax.Request('/Accessory/xhr/QuickFind/preview/'+entityType+'/'+element.value, {
onComplete: function(t){
renderPreview( entityType, t.responseText );
}});
}
function initPage()
{
new Ajax.Autocompleter("autocomplete", "resultlist",
"/Accessory/xhr/QuickFind/find/"+entityType,
{ parameters:'category=Accessories',
afterUpdateElement: loadResult }
);
}
Event.observe(window, 'load', initPage, false);
</script>