views:

126

answers:

1

I'm using YUI Autocomplete (latest version loaded using loader as of today (May 14th, 2010), which looks to be 2.8.1, with the following options:

ac = new YAHOO.widget.AutoComplete("mynode", "autocomp_node", 
              ac_ds, {typeAhead: true, forceSelection: true});

ac.itemSelectEvent.subscribe( function(type, args) { 
              alert("hey:" + args[2][1]); 
              $('#parent_id').val(args[2][1]);
});

The itemSelectEvent catches selections in AutoComplete and fills in some data on the parent.

This works on FF, Chrome, Safari, and IE8. On IE6 and IE7, however, the event never seems to trigger. To replicate: In the autocomplete field, allow it to autofill for you, then hit enter. This should select the autofill and move on to the next field (that's what it does in other browsers). With IE6 and IE7 it seems to instead trigger the form submission - the itemSelectEvent never fires (or perhaps fires after the form submission?).

Has anyone seen this? Any work-arounds?

A: 

Below is an excerpt from YUI's "AutoComplete Control: Searching Field A, Submitting Field B with itemSelectEvent" example. In reality, it is the "preventDefault" aspect of the example that is applicable. Perhaps you could use something similar to block the form submission. However, I am not sure if this would prevent other events from being fired (i.e. itemSelectEvent).

// Rather than submit the form, 
// alert the stored ID instead 
var onFormSubmit = function(e, myForm) { 
   YAHOO.util.Event.preventDefault(e); 
   alert("Company ID: " + myHiddenField.value); 
}; 
YAHOO.util.Event.addListener(YAHOO.util.Dom.get("myForm"), "submit", onFormSubmit); 
jt