diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-05-10 12:35:19 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-05-10 12:35:19 -0400 |
commit | 319c5eb2c123c24983e38cc9d9fe3058ab045cf4 (patch) | |
tree | 2ab6e914ebdb7b2fe25e58369a4a02a7239e225d /demos | |
parent | 7e239e2ab2c1147c4a14f6de36e7ecbbdf3d97e9 (diff) | |
parent | 7f8ccc523a7879428913e64f4b7eb4ace4d17a08 (diff) | |
download | jquery-ui-319c5eb2c123c24983e38cc9d9fe3058ab045cf4.tar.gz jquery-ui-319c5eb2c123c24983e38cc9d9fe3058ab045cf4.zip |
Merge branch 'master' of github.com:jquery/jquery-ui
Diffstat (limited to 'demos')
-rw-r--r-- | demos/autocomplete/combobox.html | 62 |
1 files changed, 33 insertions, 29 deletions
diff --git a/demos/autocomplete/combobox.html b/demos/autocomplete/combobox.html index ded809e1e..5fb3ffef9 100644 --- a/demos/autocomplete/combobox.html +++ b/demos/autocomplete/combobox.html @@ -16,7 +16,7 @@ <style> .ui-button { margin-left: -1px; } .ui-button-icon-only .ui-button-text { padding: 0.35em; } - .ui-autocomplete-input { margin: 0; padding: 0.48em 0 0.47em 0.45em; } + .ui-autocomplete-input { margin: 0; padding: 0.4em 0 0.4em 0.45em; } </style> <script> (function( $ ) { @@ -26,6 +26,32 @@ select = this.element.hide(), selected = select.children( ":selected" ), value = selected.val() ? selected.text() : ""; + + function removeIfInvalid(element) { + var value = $( element ).val(), + matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( value ) + "$", "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 + $( element ) + .val( "" ) + .attr( "title", value + " didn't match any item" ) + .tooltip( "open" ); + select.val( "" ); + setTimeout(function() { + input.tooltip( "close" ).attr( "title", "" ); + }, 2500 ); + input.data( "autocomplete" ).term = ""; + return false; + } + } + var input = this.input = $( "<input>" ) .insertAfter( select ) .val( value ) @@ -57,30 +83,8 @@ }); }, change: function( event, ui ) { - if ( !ui.item ) { - var value = $( this ).val(), - matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( value ) + "$", "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( "" ) - .attr( "title", value + " didn't match any item" ) - .tooltip( "open" ); - select.val( "" ); - setTimeout(function() { - input.tooltip( "close" ).attr( "title", "" ); - }, 2500 ); - input.data( "autocomplete" ).term = ""; - return false; - } - } + if ( !ui.item ) + return removeIfInvalid( this ); } }) .addClass( "ui-widget ui-widget-content ui-corner-left" ); @@ -109,6 +113,7 @@ // close if already visible if ( input.autocomplete( "widget" ).is( ":visible" ) ) { input.autocomplete( "close" ); + removeIfInvalid( input ); return; } @@ -124,10 +129,9 @@ .tooltip({ position: { of: this.button - } - }) - .tooltip( "widget" ) - .addClass( "ui-state-highlight" ); + }, + tooltipClass: "ui-state-highlight" + }); }, destroy: function() { |