From 90caa93a9b4b9b894b055cfb8dae0661ac7788b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Fri, 30 Jul 2010 12:59:33 -0400 Subject: [PATCH] Autocomplete: Respect the disabled option. Fixes #5619 - Autocomplete widget keeps looking for remote data even when it's disabled. --- .../unit/autocomplete/autocomplete_options.js | 18 ++++++++++++++++++ ui/jquery.ui.autocomplete.js | 12 ++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/unit/autocomplete/autocomplete_options.js b/tests/unit/autocomplete/autocomplete_options.js index ac4aeef35..2800fbab8 100644 --- a/tests/unit/autocomplete/autocomplete_options.js +++ b/tests/unit/autocomplete/autocomplete_options.js @@ -116,6 +116,24 @@ test("delay", function() { }, 100); }); +test("disabled", function() { + var ac = $("#autocomplete").autocomplete({ + source: data, + delay: 0, + disabled: true + }); + ac.val("ja").keydown(); + + same( $(".ui-menu:visible").length, 0 ); + + stop(); + setTimeout(function() { + same( $(".ui-menu:visible").length, 0 ); + ac.autocomplete("destroy"); + start(); + }, 50); +}); + test("minLength", function() { var ac = $("#autocomplete").autocomplete({ source: data diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index 855037824..75dfdc747 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -39,6 +39,10 @@ $.widget( "ui.autocomplete", { "aria-haspopup": "true" }) .bind( "keydown.autocomplete", function( event ) { + if ( self.options.disabled ) { + return; + } + var keyCode = $.ui.keyCode; switch( event.keyCode ) { case keyCode.PAGE_UP: @@ -88,10 +92,18 @@ $.widget( "ui.autocomplete", { } }) .bind( "focus.autocomplete", function() { + if ( self.options.disabled ) { + return; + } + self.selectedItem = null; self.previous = self.element.val(); }) .bind( "blur.autocomplete", function( event ) { + if ( self.options.disabled ) { + return; + } + clearTimeout( self.searching ); // clicks on the menu (or a button to trigger a search) will cause a blur event self.closing = setTimeout(function() {