Skip to content

Commit e7882fa

Browse files
committed
Use tooltip to display hint when combobox input doesn't match anything
1 parent 6204e1a commit e7882fa

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

demos/autocomplete/combobox.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
<script type="text/javascript" src="../../ui/jquery.ui.button.js"></script>
1111
<script type="text/javascript" src="../../ui/jquery.ui.position.js"></script>
1212
<script type="text/javascript" src="../../ui/jquery.ui.autocomplete.js"></script>
13+
<script type="text/javascript" src="../../ui/jquery.ui.tooltip.js"></script>
1314
<link type="text/css" href="../demos.css" rel="stylesheet" />
1415
<style type="text/css">
1516
/* TODO shouldn't be necessary */
@@ -41,8 +42,12 @@
4142
delay: 0,
4243
change: function(event, ui) {
4344
if (!ui.item) {
44-
// remove invalid value, as it didn't match anything
45-
$(this).val("");
45+
var value = this.value;
46+
// remove invalid value, as it didn't match anything, and display a hint
47+
$(this).val("").attr("title", value + " didn't match any item").tooltip("open");
48+
setTimeout(function() {
49+
input.tooltip("close").attr("title", "");
50+
}, 2500);
4651
return false;
4752
}
4853
select.val(ui.item.id);
@@ -54,7 +59,7 @@
5459
minLength: 0
5560
})
5661
.addClass("ui-widget ui-widget-content ui-corner-left");
57-
$("<button>&nbsp;</button>")
62+
var button = $("<button>&nbsp;</button>")
5863
.attr("tabIndex", -1)
5964
.attr("title", "Show All Items")
6065
.insertAfter(input)
@@ -75,6 +80,13 @@
7580
input.autocomplete("search", "");
7681
input.focus();
7782
});
83+
84+
input.tooltip({
85+
position: {
86+
offset: (button.width() + 5) + " 0"
87+
},
88+
tooltipClass: "ui-state-highlight"
89+
});
7890
}
7991
});
8092

themes/base/jquery.ui.tooltip.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
/* Tooltip
22
----------------------------------*/
33
.ui-tooltip {
4-
padding:8px; width:100px; position:absolute; z-index:9999;
4+
padding:8px;
5+
width:125px;
6+
position:absolute;
7+
z-index:9999;
58
-o-box-shadow: 0 0 5px #aaa;
69
-moz-box-shadow: 0 0 5px #aaa;
710
-webkit-box-shadow: 0 0 5px #aaa;

0 commit comments

Comments
 (0)