Skip to content

Commit 6fa73eb

Browse files
docs(combobox): events
1 parent 2ec8eb8 commit 6fa73eb

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

components/combobox/events.md

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,34 @@
11
---
22
title: Events
3-
page_title: DropDownList for Blazor | Events
4-
description: Events in the DropDownList for Blazor
3+
page_title: ComboBox for Blazor | Events
4+
description: Events in the ComboBox for Blazor
55
slug: components/combobox/events
6-
tags: telerik,blazor,dropdown,list,dropdownlist,events
6+
tags: telerik,blazor,combobox,combo,events
77
published: true
88
position: 20
99
---
1010

11-
# Events
11+
# ComboBox Events
1212

13-
This article explains the events available in the Telerik DropDownList for Blazor:
13+
This article explains the events available in the Telerik ComboBox for Blazor:
1414

1515
* [ValueChanged](#valuechanged)
1616
* `OnChange` - inherited event that you should not use, but you may see in the intellisense
1717

1818

1919
## ValueChanged
2020

21-
The `ValueChanged` event fires upon every change of the user selection.
21+
The `ValueChanged` event fires upon every change of the user selection. When [custom values]({%slug components/combobox/custom-value%}) are enabled, it fires upon every keystroke, like in a regular `<input>` element.
2222

23-
>note If the initial `Value` is not present in the data source, the component will select the first item of the data source and this will fire the event as well. If you do not update the field from which the `Value` is taken, you may end in an infinite loop. This scenario is most common when the initial value is `null` as data sources rarely have items with a `null` value.
24-
25-
The examples below use [binding]({%slug components/dropdownlist/databind%}) to primitive types for brevity, you can use full models as well.
23+
The examples below use [binding]({%slug components/combobox/databind%}) to primitive types for brevity, you can use full models as well.
2624

2725
>caption Handle ValueChanged
2826
2927
````CSHTML
3028
@result
3129
<br />
32-
<TelerikDropDownList Data="@MyList" ValueChanged="@( (string v) => MyValueChangeHandler(v) )">
33-
</TelerikDropDownList>
30+
<TelerikComboBox Data="@MyList" ValueChanged="@( (string v) => MyValueChangeHandler(v) )">
31+
</TelerikComboBox>
3432
3533
@code {
3634
string result;
@@ -41,25 +39,43 @@ The examples below use [binding]({%slug components/dropdownlist/databind%}) to p
4139
}
4240
4341
protected List<string> MyList = new List<string>() { "first", "second", "third" };
42+
}
43+
````
44+
45+
>caption Handle ValueChanged with custom values - the event fires on every keystroke
46+
47+
````CSHTML
48+
@result
49+
<br />
50+
<TelerikComboBox Data="@MyList" AllowCustom="true" ValueChanged="@( (string v) => MyValueChangeHandler(v) )">
51+
</TelerikComboBox>
52+
53+
@code {
54+
string result;
4455
45-
//protected string MyItem { get; set; } = "second";
56+
private void MyValueChangeHandler(string theUserChoice)
57+
{
58+
result = string.Format("The user chose: {0}", theUserChoice);
59+
}
60+
61+
protected List<string> MyList = new List<string>() { "first", "second", "third" };
4662
}
4763
````
4864

4965
@[template](/_contentTemplates/common/general-info.md#event-callback-can-be-async)
5066

5167
@[template](/_contentTemplates/common/issues-and-warnings.md#valuechanged-lambda-required)
5268

53-
>caption Handle ValueChanged and provide initial value
69+
>caption Handle ValueChanged and provide initial value (it is *not* required to enable custom values)
5470
5571
````CSHTML
56-
from the handler: @result
72+
@result
5773
<br />
5874
from model: @MyItem
5975
<br />
6076
<br />
61-
<TelerikDropDownList Data="@MyList" Value="@MyItem" ValueChanged="@( (string v) => MyValueChangeHandler(v) )">
62-
</TelerikDropDownList>
77+
<TelerikComboBox Data="@MyList" Value="@MyItem" AllowCustom="true" ValueChanged="@( (string v) => MyValueChangeHandler(v) )">
78+
</TelerikComboBox>
6379
6480
@code {
6581
string result;

components/combobox/overview.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ The ComboBox is a generic component and its type is determined by the type of th
8080
* Validation - see the [Input Validation]({%slug common-features/input-validation%}) article for more details.
8181

8282

83+
>note If the initial `Value` is not present in the data source, the component will **not** select the first item of the data source - there will simply be no selection. For such cases you may want to set `AllowCustom="true"`. This scenario is most common when the initial value is `null` as data sources rarely have items with a `null` value, and when you want to let your users type in values that are not in your predefined set of options.
8384
8485

8586
## See Also

0 commit comments

Comments
 (0)