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 + "']")
});
})
.addClass("ui-widget ui-widget-content ui-corner-left");
$("<button> </button>")
+ .attr("tabIndex", -1)
.attr("title", "Show All Items")
.insertAfter(input)
.button({
})(jQuery);
$(function() {
- $("select").combobox();
+ $("#combobox").combobox();
+ $("#toggle").click(function() {
+ $("#combobox").toggle();
+ });
});
</script>
</head>
<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>
<option value="s">scala</option>
</select>
</div>
+<button id="toggle">Show underlying select</button>
</div><!-- End demo -->