JQuery autocomplete - problem with IE8 - this tab has been restored

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

I use the combobox method, which you can find on the jQuery UI website - here

Basically, it creates an autocomplete input + a select menu from the select/option list.

I am using jQuery 1.6.4 and jQuery UI 1.8.16; as from google server.

It works fine on Chrome / FF / Opera, but does not work on IE8.

In IE8 - as soon as you select something (after entering) or use the drop-down button, IE will reload the page. Please, not that IE will not break until you click the arrows or try to choose something.

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

Real time example

Any idea what makes IE act like this? Any suggestion is 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> 
+6
source share
3 answers

I'm still trying to understand why IE8 is crashing, but it works for me when you add a jQueryUI theme to a 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 crashed into, but I still don't know why! To jQueryUI code activate: function( event, item ) {

is the following code that adds a style and attribute to the active element.

 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 it doesn't crash when deleting .addClass and .attr .

Edit 2: OK, for some reason IE is crashing with your .ui-autocomplete . If you change overflow:scroll; on overflow:auto; then IE8 will not work. Alternatively change max-height to height , which also fixes it. Guess this is a bug in IE with either max-height ( IE8: auto overflow with max-height possible) or overflow .

+3
source

At first glance, this line looks strange to me:

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

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

0
source

a quick search discovers that the script tag is missing an attribute of the required type

 <script type="text/javascript"> 

I reproduced the problem, copied the file locally without CSS and without crashing.

Odd, IF on the original page, I disabled CSS using IE developer tools, it is not crashing.

0
source

Source: https://habr.com/ru/post/899603/


All Articles