Skip to content

Commit ffc29bb

Browse files
committed
Autocomplete: Combobox demo update, fixed mustMatch with corrected change event, also added button for toggling the hidden select and an empty-value option. Fixes #5453
1 parent c01b3ba commit ffc29bb

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

demos/autocomplete/combobox.html

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,23 @@
3030
var matcher = new RegExp(request.term, "i");
3131
response(select.children("option").map(function() {
3232
var text = $(this).text();
33-
if (!request.term || matcher.test(text))
33+
if (this.value && (!request.term || matcher.test(text)))
3434
return {
35-
id: $(this).val(),
35+
id: this.value,
3636
label: text.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(request.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
3737
value: text
3838
};
3939
}));
4040
},
4141
delay: 0,
42-
select: function(e, ui) {
42+
change: function(event, ui) {
4343
if (!ui.item) {
4444
// remove invalid value, as it didn't match anything
4545
$(this).val("");
4646
return false;
4747
}
48-
$(this).focus();
4948
select.val(ui.item.id);
50-
self._trigger("selected", null, {
49+
self._trigger("selected", event, {
5150
item: select.find("[value='" + ui.item.id + "']")
5251
});
5352

@@ -56,6 +55,7 @@
5655
})
5756
.addClass("ui-widget ui-widget-content ui-corner-left");
5857
$("<button>&nbsp;</button>")
58+
.attr("tabIndex", -1)
5959
.attr("title", "Show All Items")
6060
.insertAfter(input)
6161
.button({
@@ -81,7 +81,10 @@
8181
})(jQuery);
8282

8383
$(function() {
84-
$("select").combobox();
84+
$("#combobox").combobox();
85+
$("#toggle").click(function() {
86+
$("#combobox").toggle();
87+
});
8588
});
8689
</script>
8790
</head>
@@ -91,7 +94,8 @@
9194

9295
<div class="ui-widget">
9396
<label>Your preferred programming language: </label>
94-
<select>
97+
<select id="combobox">
98+
<option value="">Select one...</option>
9599
<option value="a">asp</option>
96100
<option value="c">c</option>
97101
<option value="cpp">c++</option>
@@ -107,6 +111,7 @@
107111
<option value="s">scala</option>
108112
</select>
109113
</div>
114+
<button id="toggle">Show underlying select</button>
110115

111116
</div><!-- End demo -->
112117

0 commit comments

Comments
 (0)