Underline Matched Searches
The following example demonstrates how to underline a matched input-field search in a Kendo UI ComboBox widget.
<input id="fabric" placeholder="Select fabric..." />
<script>
function formatValue(value, text) {
var textMatcher = new RegExp(text, "ig");
return value.replace(textMatcher, function(match) {
return "<u>" + match + "</u>";
});
}
$(document).ready(function() {
// create ComboBox from input HTML element
var combo = $("#fabric").kendoComboBox({
dataTextField: "text",
dataValueField: "value",
dataSource: [
{ text: "Cotton", value: "1" },
{ text: "Polyester", value: "2" },
{ text: "Cotton/Polyester", value: "3" },
{ text: "Rib Knit", value: "4" }
],
filter: "contains",
suggest: true
}).data("kendoComboBox");
combo.setOptions({
template: $.proxy(kendo.template("#= formatValue(text, this.text()) #"), combo)
});
});
</script>
See Also
- ComboBox JavaScript API Reference
- How to Bypass Boundary Detection
- How to Configure Deferred Value Binding
- How to Expand ComboBox Located in Bootstrap Layout
- How to Implement Cascading with Local Data
- How to Make Visible Input Readonly
- How to Open ComboBox When onFocus is Triggered
- How to Prevent Adding Custom Values
- How to Select Items on Tab
For more runnable examples on the Kendo UI ComboBox, check its how-to articles.