Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(inputs): revamp events articles #1912

Merged
merged 46 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
e856eeb
docs(inputs): revamp events articles
NansiYancheva Feb 2, 2024
3691c97
–docs(inputs): update DatePicker OnCalendarCellRender event explanati…
NansiYancheva Feb 7, 2024
a76ed6e
update DateInput events
NansiYancheva Feb 7, 2024
17e5fd4
–docs(inputs): remove immediately
NansiYancheva Feb 13, 2024
0551594
–docs(inputs): improve documentation as per code styling convention
NansiYancheva Feb 13, 2024
df4523e
docs(dateinput): Final update of events docs
NansiYancheva Feb 26, 2024
f260be9
docs(datepicker): Final update of events docs plus dateinput styling
NansiYancheva Feb 26, 2024
74c378a
docs(datetimepicker): Final update of events docs plus datepicker sty…
NansiYancheva Feb 26, 2024
fcfa40e
docs(datepicker): Replace DateTime.Now with DateTime.Today
NansiYancheva Feb 26, 2024
04ae813
docs(numerictextbox): revamp events
NansiYancheva Feb 26, 2024
4106700
docs(dropdownlist) add comment to ValueChanged event to update the va…
NansiYancheva Feb 28, 2024
1ada7ba
Update components/dropdownlist/events.md
dimodi Mar 1, 2024
5856c17
Update components/dateinput/events.md
dimodi Mar 1, 2024
096bf9f
Update components/dateinput/events.md
dimodi Mar 1, 2024
a428bfd
Update components/datepicker/events.md
dimodi Mar 1, 2024
0d42078
Update components/datepicker/events.md
dimodi Mar 1, 2024
d2150a8
Update components/datepicker/events.md
dimodi Mar 1, 2024
c1734fa
Update components/datepicker/events.md
dimodi Mar 1, 2024
f55da06
Update components/datepicker/events.md
dimodi Mar 1, 2024
9fdaca6
Update components/numerictextbox/events.md
dimodi Mar 1, 2024
7eda1c4
revamp texts
NansiYancheva Mar 1, 2024
4e24bff
add APi ref
NansiYancheva Mar 1, 2024
f336af7
Update components/dateinput/events.md
dimodi Mar 5, 2024
3a7236f
Update components/datepicker/events.md
dimodi Mar 5, 2024
55d0767
Update components/datepicker/events.md
dimodi Mar 5, 2024
21d6a74
Update components/datepicker/events.md
dimodi Mar 5, 2024
f367e4e
Update components/datepicker/events.md
dimodi Mar 5, 2024
24e9bbd
Update components/datepicker/events.md
dimodi Mar 5, 2024
68a87d4
Update components/datetimepicker/events.md
dimodi Mar 5, 2024
7d8335c
Update components/datetimepicker/events.md
dimodi Mar 5, 2024
3da7b62
Update components/datetimepicker/events.md
dimodi Mar 5, 2024
279f666
Update components/datetimepicker/events.md
dimodi Mar 5, 2024
767676d
Update components/datetimepicker/events.md
dimodi Mar 5, 2024
72e4ee7
Update components/datetimepicker/events.md
dimodi Mar 5, 2024
0124e1e
Update components/numerictextbox/events.md
dimodi Mar 5, 2024
0de1dc3
Update components/numerictextbox/events.md
dimodi Mar 5, 2024
0b53071
updating valuechanged events
NansiYancheva Mar 7, 2024
45630d0
updating onchange events
NansiYancheva Mar 7, 2024
e1e961a
updatin onchange events
NansiYancheva Mar 8, 2024
fbfb421
–updating ValueChanged events
NansiYancheva Mar 8, 2024
2ff2ee0
–updating OnChange events
NansiYancheva Mar 8, 2024
12dce15
Update components/dateinput/events.md
NansiYancheva Mar 8, 2024
a1e35e3
Update components/dateinput/events.md
NansiYancheva Mar 8, 2024
34d5547
Update components/dateinput/events.md
NansiYancheva Mar 8, 2024
8e77129
Update components/dateinput/events.md
NansiYancheva Mar 8, 2024
85fa8e1
–Updating ValueChanged and OnChanged events after review
NansiYancheva Mar 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 51 additions & 71 deletions components/dateinput/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,139 +12,119 @@ position: 20

This article explains the events available in the Telerik DateInput for Blazor:

* [OnBlur](#onblur)
* [OnChange](#onchange)
* [ValueChanged](#valuechanged)
* [OnBlur](#onblur)

## OnChange

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.
## OnBlur

The date input is a generic component, so you must provide either a `Value`, or a type to the `T` parameter of the component.
The `OnBlur` event fires when the component loses focus.

>caption Handle OnChange
>caption Handle the OnBlur event

````CSHTML
@* You do not have to use OnChange to react to loss of focus *@

@result
<br />

<TelerikDateInput T="DateTime" OnChange="@MyOnChangeHandler"></TelerikDateInput>
<TelerikDateInput @bind-Value="@DateInputValue"
OnBlur="@OnBlurHandler">
</TelerikDateInput>

@code{
private string result = string.Empty;

@code {
string result;
private DateTime? DateInputValue { get; set; } = DateTime.Now;

private void MyOnChangeHandler(object theUserInput)
private void OnBlurHandler()
{
// the handler receives an object that you may need to cast to the type of the component
// if you do not provide a Value, you must provide the Type parameter to the component
result = string.Format("The user entered: {0:dd/MMM/yyyy}", (DateTime)theUserInput);
result = string.Format("BLUR fired, current value is {0:dd/MMM/yyyy}.", DateInputValue);
}
}
````

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

>tip The `OnChange` event is a custom event and does not interfere with bindings, so you can use it together with models and forms.

## OnChange

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.
NansiYancheva marked this conversation as resolved.
Show resolved Hide resolved

| Validation of input | Event handler argument | Nullable of not `Value` parameter |
| --- | --- | --- |
| Invalid input | `Null` | Nullable |
| Invalid input | Default value of the `Value` parameter | Not nullable |
| Valid input | The valid input as an object that needs to be cast to the type of the component | Nullable or not nullable |

NansiYancheva marked this conversation as resolved.
Show resolved Hide resolved
The DateInput is a generic component, so you must either provide a `Value`, or a type to the `T` parameter of the component.

>caption Handle OnChange and use two-way binding

````CSHTML
@result
<br />
model value: @theInputValue
model value: @DateInputValue
<br />

<TelerikDateInput @bind-Value="@theInputValue" OnChange="@MyOnChangeHandler"></TelerikDateInput>
<TelerikDateInput @bind-Value="@DateInputValue"
OnChange="@MyOnChangeHandler">
</TelerikDateInput>

@code {
string result;
private string result = string.Empty;

DateTime? theInputValue { get; set; } = DateTime.Now;
private DateTime? DateInputValue { get; set; } = DateTime.Now;

private void MyOnChangeHandler(object theUserInput)
private void MyOnChangeHandler(object userInput)
{
// the handler receives an object that you may need to cast to the type of the component
// if you do not provide a Value, you must provide the Type parameter to the component
result = string.Format("The user entered: {0:dd/MMM/yyyy}", (theUserInput as DateTime?).Value);
result = string.Format("The user entered: {0:dd/MMM/yyyy}", (DateTime)userInput);
}
}
````

## ValueChanged

The `ValueChanged` event fires upon every change (for example, keystroke) in the input.

>caption Handle ValueChanged

````CSHTML
@result
<br />
@[template](/_contentTemplates/common/general-info.md#event-callback-can-be-async)

<TelerikDateInput ValueChanged="@( (DateTime d) => MyValueChangeHandler(d) )"></TelerikDateInput>
>tip The `OnChange` event is a custom event and does not interfere with bindings, so you can use it together with models and forms.

@code {
string result;

private void MyValueChangeHandler(DateTime theUserInput)
{
result = string.Format("The user entered: {0}", theUserInput);
}
}
````
## ValueChanged

@[template](/_contentTemplates/common/general-info.md#event-callback-can-be-async)
The `ValueChanged` event fires on every typing in the input and if the input is valid. The handler will receive the valid input.
NansiYancheva marked this conversation as resolved.
Show resolved Hide resolved

@[template](/_contentTemplates/common/issues-and-warnings.md#valuechanged-lambda-required)
The event also fires if the input is invalid and when the input loses focus and the `Value` parameter is nullable. The handler will receive a `null` argument.
NansiYancheva marked this conversation as resolved.
Show resolved Hide resolved

>caption Handle ValueChanged and provide initial value

````CSHTML
@result
<br />
model value: @theInputValue
model value: @DateInputValue
<br />

<TelerikDateInput Value="@theInputValue" ValueChanged="@( (DateTime d) => MyValueChangeHandler(d) )"></TelerikDateInput>
<TelerikDateInput Value="@DateInputValue"
ValueChanged="@( (DateTime d) => MyValueChangeHandler(d) )">
</TelerikDateInput>

@code {
string result;
private string result = string.Empty;

DateTime theInputValue { get; set; } = DateTime.Now;
private DateTime DateInputValue { get; set; } = DateTime.Now;

private void MyValueChangeHandler(DateTime theUserInput)
private void MyValueChangeHandler(DateTime userInput)
{
result = string.Format("The user entered: {0:dd/MMM/yyyy}", theUserInput);
result = string.Format("The user entered: {0:dd/MMM/yyyy}", userInput);

//you have to update the model manually because handling the ValueChanged event does not let you use @bind-Value
theInputValue = theUserInput;
DateInputValue = userInput;
}
}
````

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

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

## OnBlur

The `OnBlur` event fires when the component loses focus.

>caption Handle the OnBlur event

````CSHTML
@* You do not have to use OnChange to react to loss of focus *@

<TelerikDateInput @bind-Value="@TheDate"
OnBlur="@OnBlurHandler">
</TelerikDateInput>

@code{
async Task OnBlurHandler()
{
Console.WriteLine($"BLUR fired, current value is {TheDate}.");
}

DateTime? TheDate { get; set; } = DateTime.Now;
}
````

## See Also

Expand Down
Loading
Loading