Skip to content

Commit 4999b2c

Browse files
github-actions[bot]KB Bot
andauthored
Added new kb article filtering-checkboxes-radcombobox-typing (#707)
Co-authored-by: KB Bot <[email protected]>
1 parent 1ed1cdf commit 4999b2c

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
title: Implementing CheckBox Filtering in RadComboBox When Typing
3+
description: Learn how to use the OnClientBlur event to implement checkbox filtering functionality in RadComboBox based on typed input.
4+
type: how-to
5+
page_title: Filtering CheckBoxes in RadComboBox While Typing
6+
meta_title: Filtering CheckBoxes in RadComboBox While Typing
7+
slug: filtering-checkboxes-radcombobox-typing
8+
tags: combobox, ui for asp.net ajax, client-side, checkboxes, filtering
9+
res_type: kb
10+
ticketid: 1695228
11+
---
12+
13+
## Environment
14+
15+
<table>
16+
<tbody>
17+
<tr>
18+
<td>Product</td>
19+
<td>ComboBox for UI for ASP.NET AJAX</td>
20+
</tr>
21+
<tr>
22+
<td>Version</td>
23+
<td>All</td>
24+
</tr>
25+
</tbody>
26+
</table>
27+
28+
## Description
29+
30+
I need to implement dynamic checkbox selection in a [RadComboBox](https://www.telerik.com/products/aspnet-ajax/documentation/controls/combobox/overview) based on typed input. When typing in the input field, items matching the entered text should be checked. If the input is cleared or modified, items that no longer match should be unchecked.
31+
32+
For instance, typing "St" should check all items containing "St". Further typing, such as "Stain", should narrow the selection down to items containing "Stain".
33+
34+
## Solution
35+
36+
To achieve this, use the `OnClientBlur` event of RadComboBox. This event fires when the combobox loses focus, enabling client-side filtering and checkbox selection:
37+
38+
1. Configure the RadComboBox with `CheckBoxes="true"` and `AllowCustomText="true"`.
39+
2. Define the `OnClientBlur` event to handle the filtering logic.
40+
3. Use the client-side API to loop through the items and check/uncheck based on the typed input.
41+
42+
````ASP.NET
43+
<telerik:RadComboBox ID="drpConfig" runat="server" CheckBoxes="true" OnClientBlur="onClientBlur" AllowCustomText="true">
44+
<Items>
45+
<telerik:RadComboBoxItem Text="SteelA36" />
46+
<telerik:RadComboBoxItem Text="SteelA572" />
47+
<telerik:RadComboBoxItem Text="Stainless304" />
48+
<telerik:RadComboBoxItem Text="Stainless316" />
49+
<telerik:RadComboBoxItem Text="Aluminum6061" />
50+
<telerik:RadComboBoxItem Text="Aluminum7075" />
51+
</Items>
52+
</telerik:RadComboBox>
53+
````
54+
55+
````JavaScript
56+
function onClientBlur(sender, args) {
57+
let text = sender.get_text().toLowerCase();
58+
let items = sender.get_items();
59+
60+
items.forEach((item) => {
61+
let itemText = item.get_text().toLowerCase();
62+
63+
itemText.indexOf(text) !== -1 ? item.set_checked(true) : item.set_checked(false);
64+
});
65+
}
66+
````
67+
68+
Important Notes
69+
70+
- Using `AllowCustomText` with `CheckBoxes` is not fully supported and may lead to unexpected behavior. However, it works reliably for this specific scenario.
71+
- Ensure that the `AutoPostBack` property is set to `false` to avoid unnecessary server-side actions.
72+
73+
## See Also
74+
75+
- [RadComboBox Client-Side Programming Documentation](https://www.telerik.com/products/aspnet-ajax/documentation/controls/combobox/client-side-programming/overview)
76+
- [RadComboBox OnClientBlur Event](https://www.telerik.com/products/aspnet-ajax/documentation/controls/combobox/client-side-programming/events/onclientblur)
77+

0 commit comments

Comments
 (0)