Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #2116 (closed defect: fixed)

Opened 3 years ago

Last modified 2 years ago

[PATCH] Controls.js Autocompleter.Base.updateElement() hook

Reported by: rob.wills@gmail.com Assigned to: thomas@fesch.at
Priority: normal Milestone:
Component: script.aculo.us Version:
Severity: normal Keywords: control.js Ajax Autocompleter
Cc:

Description

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>

Attachments

control_AutocompleterBaseUpdateElement.diff (422 bytes) - added by anonymous on 09/03/05 21:03:19.
Javascript Diff

Change History

09/03/05 21:03:19 changed by anonymous

  • attachment control_AutocompleterBaseUpdateElement.diff added.

Javascript Diff

09/03/05 21:10:43 changed by rob.wills@gmail.com

I didn't realise I can't edit the ticket to fix the embedded links :(

Quicktime movie wouldn't load into the ticket anyway... it's over here (720KB)

09/04/05 05:35:41 changed by rob.wills@gmail.com

Thomas, the patch needs a small adjustment — the arguments to the hook function should be:

this.options.afterUpdateElement(this.element, selectedElement);

This allows the hook to investigate the selected element for it's value or id. I overload the id attribute to make it behave like a value attribute of a select option:

    function loadResult(element,selectedElement)
    {
        var entityParts = selectedElement.id.split('::');
        var entityType = entityParts[0];
        var entityId   = entityParts[1];
        ...
    }

Where the id looks like id="Supplier::87" .

09/05/05 15:43:33 changed by madrobby

  • status changed from new to closed.
  • resolution set to fixed.

03/20/06 01:35:11 changed by anonymous

  • keywords changed from control.js Ajax Autocompleter to control.js Ajax Autocompleter.

08/30/06 00:02:13 changed by Janet

  • severity changed from normal to 1.
  • cc set to Janet.
  • component changed from script.aculo.us to 1.
  • summary changed from [PATCH] Controls.js Autocompleter.Base.updateElement() hook to Janet.
  • priority changed from normal to 1.
  • version set to 1.
  • milestone set to 1.
  • keywords changed from control.js Ajax Autocompleter to Janet.
  • type changed from defect to 1.

08/30/06 01:12:26 changed by anonymous

  • severity changed from 1 to normal.
  • cc deleted.
  • component changed from 1 to script.aculo.us.
  • summary changed from Janet to [PATCH] Controls.js Autocompleter.Base.updateElement() hook.
  • priority changed from 1 to normal.
  • version deleted.
  • milestone deleted.
  • keywords changed from Janet to control.js Ajax Autocompleter.
  • type changed from 1 to defect.

reverse spam