jQuery autocomplete - IE8 issue - this tab has been recovered
Asked Answered
L

3

6

I run into a problem with jQuery UI - Autocomplete and IE8.

I'm using combobox method which you can find on jQuery UI website - here
Basically, it is creating autocomplete input + select menu from select/option list.

I'm using jQuery 1.6.4 and jQuery UI 1.8.16; both from google server.

It is working perfectly on Chrome / FF / Opera, but does not work on IE8.

On IE8 - once you select something (after typing), or use dropdown button IE will reload the page. Please not that IE will not crash till you use arrows or try to select something.

  • res://ieframe.dll/acr_error.htm#, in the URL, in front of the actual path
  • or a message this tab has been reloaded; a problem with the page causes IE to close and reopen the page

Live example here

Any idea what is causing IE to act like that? Any suggestion much appreciated.


jQuery code:

    <script>
    (function( $ ) {
        $.widget( "ui.combobox", {
            _create: function() {
                var self = this,
                    select = this.element.hide(),
                    selected = select.children( ":selected" ),
                    value = selected.val() ? selected.text() : "";
                var input = this.input = $( "<input>" )
                    .insertAfter( select )
                    .val( value )
                    .autocomplete({
                        delay: 0,
                        minLength: 0,
                        source: function( request, response ) {
                            var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" );
                            response( select.children( "option" ).map(function() {
                                var text = $( this ).text();
                                if ( this.value && ( !request.term || matcher.test(text) ) )
                                    return {
                                        label: text.replace(
                                            new RegExp(
                                                "(?![^&;]+;)(?!<[^<>]*)(" +
                                                $.ui.autocomplete.escapeRegex(request.term) +
                                                ")(?![^<>]*>)(?![^&;]+;)", "gi"
                                            ), "<strong>$1</strong>" ),
                                        value: text,
                                        option: this
                                    };
                            }) );
                        },
                        select: function( event, ui ) {
                            ui.item.option.selected = true;
                            self._trigger( "selected", event, {
                                item: ui.item.option
                            });
                        },
                        change: function( event, ui ) {
                            if ( !ui.item ) {
                                var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
                                    valid = false;
                                select.children( "option" ).each(function() {
                                    if ( $( this ).text().match( matcher ) ) {
                                        this.selected = valid = true;
                                        return false;
                                    }
                                });
                                if ( !valid ) {
                                    // remove invalid value, as it didn't match anything
                                    $( this ).val( "" );
                                    select.val( "" );
                                    input.data( "autocomplete" ).term = "";
                                    return false;
                                }
                            }
                        }
                    })
                    .addClass( "ui-widget ui-widget-content ui-corner-left" );

                input.data( "autocomplete" )._renderItem = function( ul, item ) {
                    return $( "<li></li>" )
                        .data( "item.autocomplete", item )
                        .append( "<a>" + item.label + "</a>" )
                        .appendTo( ul );
                };

                this.button = $( "<button type='button'>&nbsp;</button>" )
                    .attr( "tabIndex", -1 )
                    .attr( "title", "Show All Items" )
                    .insertAfter( input )
                    .button({
                        text: false
                    })
                    .removeClass( "ui-corner-all" )
                    .click(function() {
                        // close if already visible
                        if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
                            input.autocomplete( "close" );
                            return;
                        }

                        // work around a bug (likely same cause as #5265)
                        $( this ).blur();

                        // pass empty string as value to search for, displaying all results
                        input.autocomplete( "search", "" );
                        input.focus();
                    });
            },

            destroy: function() {
                this.input.remove();
                this.button.remove();
                this.element.show();
                $.Widget.prototype.destroy.call( this );
            }
        });
    })( jQuery );

    $(document).ready( function() {

        $("#combobox").combobox();

    });


    </script>
Luedtke answered 19/10, 2011 at 10:59 Comment(0)
N
3

I'm still trying to work out why IE8 is crashing but it does work for me when you add a jQueryUI theme to the page, for example:

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/cupertino/jquery-ui.css">

Edit: I think I know which line it is crashing on, but I still do not know why! In the jQueryUI code activate: function( event, item ) {

is the following code which adds style and an attribute to the active item.

this.active = item.eq(0)
    .children("a")
    .addClass("ui-state-hover")
    .attr("id", "ui-active-menuitem")
    .end();

For some reason, IE8 crashes here, although for me sometimes does not crash when I remove the .addClass and .attr lines.

Edit 2: OK, for some reason IE is crashing with your .ui-autocomplete style. If you change overflow:scroll; to overflow:auto; then IE8 does not crash. Alternatively change max-height to just height, which also fixes it. Guess it's a bug in IE either with max-height (maybe IE8 overflow:auto with max-height) or overflow.

Nava answered 29/10, 2011 at 16:54 Comment(0)
G
0

From the first glance this line look strange to me:

   if ( this.value && ( !request.term || matcher.test(text) ) )
       return {

But its working fine for me in ie8, in ie7 its not working at all. Try if(){return{...}}.

Goddess answered 19/10, 2011 at 11:18 Comment(1)
When made this change as you suggested - script fails (all competed values are undefined)Luedtke
P
0

quick look finds your script tag is missing required type attribute

<script type="text/javascript">

I reproduced the issue, copied the file local with no CSS and no fails.

Odd, IF on the original page, I disable CSS using the IE developer tools, it does not crash.

Periodicity answered 19/10, 2011 at 13:41 Comment(5)
Yes, it does. Thanks. This doesn't fix the issue sadly.Luedtke
If you ran a quick test to use jQuery version 1.6.4 does it still fail? (the page has 1.4.3 on it at the moment)Periodicity
Yes it does. It had 1.6.4 in the first place. It is very odd as I'm using original code from jQuery UI examples.Luedtke
Confirmed the 1.6.4, and the fail on my browser. REAL odd that IF I pull this local to my machine, it does not fail - I do not have the source of your CSS file and the images referenced there. Is it possible to in-line that and remove the image references? (to try to replicate from my local machine.)Periodicity
copy of all of the files here: dl.dropbox.com/u/17683975/AutoCompleteIE.zipLuedtke

© 2022 - 2024 — McMap. All rights reserved.