Skip to content

Commit 723e0d6

Browse files
committed
Autocomplete demo (combobox): Fixed tooltips and clearing of select on invalid entry.
1 parent da1517e commit 723e0d6

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

demos/autocomplete/combobox.html

+19-9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
var input = this.input = $( "<input>" )
3030
.insertAfter( select )
3131
.val( value )
32+
.attr( "title", "" )
3233
.autocomplete({
3334
delay: 0,
3435
minLength: 0,
@@ -57,7 +58,8 @@
5758
},
5859
change: function( event, ui ) {
5960
if ( !ui.item ) {
60-
var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ),
61+
var value = $( this ).val(),
62+
matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( value ) + "$", "i" ),
6163
valid = false;
6264
select.children( "option" ).each(function() {
6365
if ( $( this ).text().match( matcher ) ) {
@@ -67,8 +69,12 @@
6769
});
6870
if ( !valid ) {
6971
// remove invalid value, as it didn't match anything
70-
$(this).val( "").attr( "title", value + " didn't match any item" ).tooltip( "open" );
71-
setTimeout( function() {
72+
$( this )
73+
.val( "" )
74+
.attr( "title", value + " didn't match any item" )
75+
.tooltip( "open" );
76+
select.val( "" );
77+
setTimeout(function() {
7278
input.tooltip( "close" ).attr( "title", "" );
7379
}, 2500 );
7480
input.data( "autocomplete" ).term = "";
@@ -89,6 +95,7 @@
8995
this.button = $( "<button type='button'>&nbsp;</button>" )
9096
.attr( "tabIndex", -1 )
9197
.attr( "title", "Show All Items" )
98+
.tooltip()
9299
.insertAfter( input )
93100
.button({
94101
icons: {
@@ -109,12 +116,15 @@
109116
input.autocomplete( "search", "" );
110117
input.focus();
111118
});
112-
113-
input.tooltip( {
114-
position: {
115-
offset: (this.button.width() + 5) + " 0"
116-
}
117-
}).tooltip( "widget" ).addClass( "ui-state-highlight" );
119+
120+
input
121+
.tooltip({
122+
position: {
123+
of: this.button
124+
}
125+
})
126+
.tooltip( "widget" )
127+
.addClass( "ui-state-highlight" );
118128
},
119129

120130
destroy: function() {

0 commit comments

Comments
 (0)