Skip to content

Commit

Permalink
Autocomplete: Combobox demo update, fixed mustMatch with corrected ch…
Browse files Browse the repository at this point in the history
…ange event, also added button for toggling the hidden select and an empty-value option. Fixes #5453
  • Loading branch information
jzaefferer committed Apr 8, 2010
1 parent c01b3ba commit ffc29bb
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions demos/autocomplete/combobox.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,23 @@
var matcher = new RegExp(request.term, "i");
response(select.children("option").map(function() {
var text = $(this).text();
if (!request.term || matcher.test(text))
if (this.value && (!request.term || matcher.test(text)))
return {
id: $(this).val(),
id: this.value,
label: text.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + $.ui.autocomplete.escapeRegex(request.term) + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "<strong>$1</strong>"),
value: text
};
}));
},
delay: 0,
select: function(e, ui) {
change: function(event, ui) {
if (!ui.item) {
// remove invalid value, as it didn't match anything
$(this).val("");
return false;
}
$(this).focus();
select.val(ui.item.id);
self._trigger("selected", null, {
self._trigger("selected", event, {
item: select.find("[value='" + ui.item.id + "']")
});

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

$(function() {
$("select").combobox();
$("#combobox").combobox();
$("#toggle").click(function() {
$("#combobox").toggle();
});
});
</script>
</head>
Expand All @@ -91,7 +94,8 @@

<div class="ui-widget">
<label>Your preferred programming language: </label>
<select>
<select id="combobox">
<option value="">Select one...</option>
<option value="a">asp</option>
<option value="c">c</option>
<option value="cpp">c++</option>
Expand All @@ -107,6 +111,7 @@
<option value="s">scala</option>
</select>
</div>
<button id="toggle">Show underlying select</button>

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

Expand Down

0 comments on commit ffc29bb

Please sign in to comment.