Skip to content

Commit 138e656

Browse files
dimodidimodi
authored andcommitted
docs(DateTimePicker): Improve OnChange documentation
1 parent 8b55498 commit 138e656

File tree

2 files changed

+33
-29
lines changed

2 files changed

+33
-29
lines changed

components/datetimepicker/events.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,33 +102,34 @@ As an argument, the event handler receives a [`DateTimePickerCalendarCellRenderE
102102

103103
## OnChange
104104

105-
The `OnChange` event represents a user action that confirms the current value. It fires when the user presses `Enter` in the input or when the input loses focus.
105+
The `OnChange` event represents a user action that confirms the current value. It fires when the user:
106+
107+
* Presses `Enter` while the textbox is focused.
108+
* Clicks **Set** in the date and time selection popup.
109+
* Blurs the component.
106110

107111
The event handler receives an `object` argument that you need to cast to the actual `Value` type. The argument can hold a value or be `null`, depending on the user input and the `Value` type.
108112

109113
The DateTimePicker is a generic component, so you must either provide a `Value`, or a type to the `T` parameter of the component.
110114

111-
>caption Handle OnChange and use two-way binding
115+
>caption Handle DateTimePicker OnChange and use two-way Value binding
112116
113117
````RAZOR
114-
@result
115-
<br />
116-
model value: @DateTimePickerValue
117-
<br />
118-
119118
<TelerikDateTimePicker @bind-Value="@DateTimePickerValue"
120-
OnChange="@MyOnChangeHandler">
119+
OnChange="@DateTimePickerValueChanged"
120+
Width="300px">
121121
</TelerikDateTimePicker>
122122
123-
@code {
124-
private string result = string.Empty;
123+
<span><code>OnChange</code> fired at <strong>@LastOnChange?.ToString("HH:mm:ss.fff")</strong></span>
125124
126-
private DateTime? DateTimePickerValue { get; set; } = DateTime.Now;
125+
@code {
126+
private DateTime? DateTimePickerValue { get; set; }
127+
private DateTime? LastOnChange { get; set; }
127128
128-
private void MyOnChangeHandler(object userInput)
129+
private void DateTimePickerValueChanged(object currentValue)
129130
{
130-
// if you do not provide a Value, you must provide the Type parameter to the component
131-
result = string.Format("The user entered: {0}", (DateTime)userInput);
131+
LastOnChange = DateTime.Now;
132+
Console.WriteLine($"The current Value is {(DateTime?)currentValue}");
132133
}
133134
}
134135
````

components/timepicker/events.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -52,31 +52,34 @@ TimePicker Value: @TimePickerValue
5252

5353
## OnChange
5454

55-
The `OnChange` event represents a user action - confirmation of the current value. It fires when the user presses `Enter` in the input, or when the input loses focus.
55+
The `OnChange` event represents a user action that confirms the current value. It fires when the user:
5656

57-
The time picker is a generic component, so you must provide either a `Value`, or a type to the `T` parameter of the component.
57+
* Presses `Enter` while the textbox is focused.
58+
* Clicks **Set** in the time selection popup.
59+
* Blurs the component.
5860

59-
>caption Handle the TimePicker OnChange event
61+
The event handler receives an `object` argument that you need to cast to the actual `Value` type. The argument can hold a value or be `null`, depending on the user input and the `Value` type.
6062

61-
````RAZOR
62-
@Result
63-
<br />
64-
TimePicker Value: @TimePickerValue
65-
<br />
63+
The TimePicker is a generic component, so you must either provide a `Value`, or a type to the `T` parameter of the component.
64+
65+
>caption Handle DateTimePicker OnChange and use two-way Value binding
6666
67+
````RAZOR
6768
<TelerikTimePicker @bind-Value="@TimePickerValue"
68-
OnChange="OnTimePickerChange">
69+
OnChange="@TimePickerValueChanged"
70+
Width="150px">
6971
</TelerikTimePicker>
7072
71-
@code {
72-
private string Result { get; set; } = string.Empty;
73+
<span><code>OnChange</code> fired at <strong>@LastOnChange?.ToString("HH:mm:ss.fff")</strong></span>
7374
74-
private DateTime TimePickerValue { get; set; } = DateTime.Now;
75+
@code {
76+
private DateTime? TimePickerValue { get; set; }
77+
private DateTime? LastOnChange { get; set; }
7578
76-
private void OnTimePickerChange(object currentValue)
79+
private void TimePickerValueChanged(object currentValue)
7780
{
78-
// Cast the event argument to the actual value type
79-
Result = $"The user entered: {(DateTime)currentValue}";
81+
LastOnChange = DateTime.Now;
82+
Console.WriteLine($"The current Value is {(DateTime?)currentValue}");
8083
}
8184
}
8285
````

0 commit comments

Comments
 (0)