Skip to content

Commit edb4b3b

Browse files
983104: Updated
1 parent ce601d8 commit edb4b3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+857
-528
lines changed

blazor/datepicker/data-binding.md

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ This section explains how to bind values to the DatePicker component in the foll
1717

1818
## One-way binding
1919

20-
Bind a value to the DatePicker component using the `Value` property as shown in the following example. In one-way binding, pass the property or variable name prefixed with `@` (for example, `@DateValue`). Changes to the source update the UI, but user edits do not update the source automatically.
20+
Bind a value to the DatePicker component using the `Value` property as shown in the following example. In one-way binding, pass the property or variable name prefixed with `@` (for example, `@DateValue`). Changes to the source update the UI, but edits in the UI do not update the source automatically.
21+
22+
- API reference: [Value](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Calendars.SfDatePicker-1.html#Syncfusion_Blazor_Calendars_SfDatePicker_1_Value)
2123

2224
```cshtml
2325
@using Syncfusion.Blazor.Calendars
@@ -27,7 +29,7 @@ Bind a value to the DatePicker component using the `Value` property as shown in
2729
<button @onclick="@UpdateValue">Update Value</button>
2830
2931
@code {
30-
public DateTime? DateValue {get;set;} = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 28);
32+
public DateTime? DateValue { get; set; } = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 28);
3133
3234
public void UpdateValue()
3335
{
@@ -36,10 +38,18 @@ Bind a value to the DatePicker component using the `Value` property as shown in
3638
}
3739
```
3840

41+
Preview:
42+
- The DatePicker initially shows the 28th of the current month. Selecting the “Update Value” button sets the input to today’s date. Typing or selecting a date in the UI does not change the underlying DateValue field.
43+
3944
## Two-way data binding
4045

4146
Two-way binding is achieved with the `@bind-Value` attribute. This binds the component’s value to the specified field and updates both the UI and the source when changes occur. Use a type that matches the component’s `TValue` (for example, `DateTime` or `DateTime?`). Clearing the input sets the value to `null` when using a nullable type. The `@bind-Value` syntax is shorthand for using the `Value`, `ValueChanged`, and `ValueExpression` parameters.
4247

48+
- API references:
49+
- [Value](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Calendars.SfDatePicker-1.html#Syncfusion_Blazor_Calendars_SfDatePicker_1_Value)
50+
- [ValueChanged](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Calendars.SfDatePicker-1.html#Syncfusion_Blazor_Calendars_SfDatePicker_1_ValueChanged)
51+
- [ValueExpression](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Calendars.SfDatePicker-1.html#Syncfusion_Blazor_Calendars_SfDatePicker_1_ValueExpression)
52+
4353
```cshtml
4454
@using Syncfusion.Blazor.Calendars
4555
@@ -48,31 +58,37 @@ Two-way binding is achieved with the `@bind-Value` attribute. This binds the com
4858
<SfDatePicker TValue="DateTime?" @bind-Value="@DateValue"></SfDatePicker>
4959
5060
@code {
51-
public DateTime? DateValue { get; set; } = DateTime.Now;
61+
public DateTime? DateValue { get; set; } = DateTime.Now;
5262
}
5363
```
5464

65+
Preview:
66+
- The paragraph renders the current value from the bound field. Selecting a new date in the DatePicker updates the paragraph text immediately. Clearing the input results in a blank (null) display when using a nullable type.
67+
5568
## Dynamic value binding
5669

57-
The value can be updated programmatically in response to component events (such as the DatePicker’s `ValueChange`) or from external logic. When updating state within component event callbacks, the UI re-renders automatically in most cases; `StateHasChanged()` is typically required only when changes originate outside the normal event pipeline (for example, from timers, external services, or non-UI threads). The following example shows updating the value in the DatePicker’s `ValueChange` event.
70+
The value can be updated programmatically in response to component events (such as the DatePicker’s `ValueChange`) or from external logic. When updating state within component event callbacks, the UI re-renders automatically.
71+
72+
- API references:
73+
- [ValueChange event](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Calendars.SfDatePicker-1.html#Syncfusion_Blazor_Calendars_SfDatePicker_1_ValueChange)
74+
- [ChangedEventArgs<TValue>](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Calendars.ChangedEventArgs-1.html)
5875

5976
```cshtml
6077
@using Syncfusion.Blazor.Calendars
6178
6279
<p>DatePicker value is: @DateValue</p>
6380
6481
<SfDatePicker TValue="DateTime?" Value="@DateValue">
65-
<DatePickerEvents TValue="DateTime?" ValueChange="@onChange"></DatePickerEvents>
82+
<DatePickerEvents TValue="DateTime?" ValueChange="@OnChange"></DatePickerEvents>
6683
</SfDatePicker>
6784
6885
@code {
86+
public DateTime? DateValue { get; set; } = DateTime.Now;
6987
70-
public DateTime? DateValue { get; set; } = DateTime.Now;
71-
72-
private void onChange(Syncfusion.Blazor.Calendars.ChangedEventArgs<DateTime?> args)
88+
private void OnChange(Syncfusion.Blazor.Calendars.ChangedEventArgs<DateTime?> args)
7389
{
7490
DateValue = args.Value;
75-
StateHasChanged();
91+
// StateHasChanged() is not required here because event callbacks trigger re-rendering.
7692
}
7793
}
78-
```
94+

blazor/datepicker/date-format.md

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,64 @@
11
---
22
layout: post
3-
title: Date Format in Blazor DatePicker Component | Syncfusion
3+
title: Date Format in Blazor DatePicker Component | Syncfusion
44
description: Checkout and learn here all about Date Format in Syncfusion Blazor DatePicker component and much more.
55
platform: Blazor
66
control: DatePicker
77
documentation: ug
88
---
99

10-
# Date Format in Blazor DatePicker Component
10+
# Date Format in Blazor DatePicker Component
11+
12+
This article describes how to control the display and input formats in the Blazor DatePicker component using the Format and InputFormats properties, along with .NET standard and custom date-time format strings.
1113

1214
## Display Format
1315

14-
The display format specifies how a date value is rendered in the DatePicker input. Use it to control the visual representation of the selected value (for example, dd-MM-yyyy, MM/dd/yyyy, or MMM dd, yyyy).
16+
The display format specifies how a date value is rendered in the DatePicker input. This controls the visual representation of the selected value (for example, dd-MM-yyyy, MM/dd/yyyy, or MMM dd, yyyy).
17+
18+
By default, the DatePicker display format is based on the current culture. A custom or standard .NET date and time format string can be applied using the [Custom Format](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) or [Standard Format](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings) options via the [Format](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Calendars.SfDatePicker-1.html#Syncfusion_Blazor_Calendars_SfDatePicker_1_Format) property.
1519

16-
By default, the DatePicker's display format is based on the current culture. A custom or standard .NET date and time format string can be applied using the [Custom Format](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) or [Standard Format](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings) options via the [Format](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Calendars.SfDatePicker-1.html#Syncfusion_Blazor_Calendars_SfDatePicker_1_Format) property.
20+
Note: When a display format is set, it consistently controls how the value is shown, regardless of culture-specific date order or separators. The underlying value type remains DateTime/DateTime?, and localized month/day names still follow the active culture where applicable.
1721

18-
> When a display format is set, it consistently controls how the value is shown, regardless of culture-specific date order or separators. The underlying value type remains DateTime/DateTime?, and localized month/day names still follow the active culture where applicable.
22+
```cshtml
23+
@using Syncfusion.Blazor.Calendars
1924
20-
{% highlight Razor %}
25+
<p>Selected date (display format): @DateValue</p>
2126
22-
{% include_relative code-snippet/DatePicker.razor %}
27+
<SfDatePicker TValue="DateTime?"
28+
Value="@DateValue"
29+
Format="MMM dd, yyyy">
30+
</SfDatePicker>
2331
24-
{% endhighlight %}
32+
@code {
33+
public DateTime? DateValue { get; set; } = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 15);
34+
}
35+
```
2536

37+
Preview:
38+
- The input renders the selected date in the form “Sep 15, 2025” (based on the chosen format), while the bound value remains a DateTime?.
2639

2740
![Date Format in Blazor DatePicker](./images/DatePicker.png)
2841

2942
## Input Formats
3043

31-
The input format defines how users can type dates that will be parsed into a valid value in the DatePicker.
44+
The input format defines how typed dates are parsed into a valid DatePicker value. Typed input is interpreted according to the current culture and any configured input patterns. After input is confirmed (for example, by pressing Enter or Tab, or when the input loses focus), the value is reformatted using the display format.
45+
46+
Multiple input patterns can be accepted by specifying [.NET custom](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) or [standard](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings) patterns in the [InputFormats](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Calendars.SfDatePicker-1.html#Syncfusion_Blazor_Calendars_SfDatePicker_1_InputFormats) property (for example, d-M-yy, d/M/yyyy, yyyy-MM-dd).
3247

33-
Typed input is parsed according to the current culture and any formats specified. After the user confirms input (for example, by pressing Enter or Tab, or when the input loses focus), the value is reformatted and displayed using the configured display format. You can specify [.NET custom](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings) or [standard](https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings) patterns in the [InputFormats](https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Calendars.SfDatePicker-1.html#Syncfusion_Blazor_Calendars_SfDatePicker_1_InputFormats) property to accept multiple input patterns (for example, d-M-yy, d/M/yyyy, yyyy-MM-dd).
48+
```cshtml
49+
@using Syncfusion.Blazor.Calendars
3450
35-
{% highlight Razor %}
51+
<p>Selected date (input formats): @DateValue</p>
3652
37-
{% include_relative code-snippet/InputFormat.razor %}
53+
<SfDatePicker TValue="DateTime?"
54+
Value="@DateValue"
55+
Format="dd-MM-yyyy"
56+
InputFormats="@(new string[] { "d-M-yy", "d/M/yyyy", "yyyy-MM-dd" })">
57+
</SfDatePicker>
3858
39-
{% endhighlight %}
59+
@code {
60+
public DateTime? DateValue { get; set; } = DateTime.Today;
61+
}
62+
```
63+
Preview:
64+
- The input accepts dates typed as “1-9-25”, “01/09/2025”, or “2025-09-01”. After confirmation, the value is reformatted and displayed as “01-09-2025” according to the configured Format “dd-MM-yyyy”.

blazor/datepicker/dateonly-support.md

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,42 @@ The [DateOnly](https://learn.microsoft.com/en-us/dotnet/api/system.dateonly?view
1414
> The Blazor DatePicker component supports the `DateOnly` type in .NET 7 and later. Although DateOnly was introduced in .NET 6, full support in Blazor requires .NET 7 due to serialization and model binding changes.
1515
1616
Key points when using DateOnly:
17-
- Set the component’s TValue to `DateOnly` (or `DateOnly?` for nullable scenarios and clearing values).
17+
- Set the component’s `TValue` to `DateOnly` (or `DateOnly?` for nullable scenarios and clearing values).
1818
- Use `@bind-Value` for two-way binding with a DateOnly model property.
19-
- Ensure related properties (such as Min, Max, and Value) use compatible types when working with DateOnly.
19+
- Ensure related properties (such as `Min`, `Max`, and `Value`) use compatible types when working with DateOnly.
2020
- Formatting and parsing follow the current culture; DateOnly represents dates only and does not include time.
2121

22-
{% highlight Razor %}
22+
```cshtml
23+
@using Syncfusion.Blazor.Calendars
2324
24-
{% include_relative code-snippet/DateOnly.razor %}
25+
<p>Selected date: @DateValue</p>
2526
26-
{% endhighlight %}
27+
<SfDatePicker TValue="DateOnly?"
28+
@bind-Value="DateValue"
29+
Format="yyyy-MM-dd"
30+
Min="@MonthStart"
31+
Max="@MonthEnd">
32+
</SfDatePicker>
2733
28-
![Blazor DatePicker with DateOnly](./images/DatePickerDateOnly.gif)
34+
@code {
35+
// Initial value
36+
public DateOnly? DateValue { get; set; } =
37+
new DateOnly(DateTime.Now.Year, DateTime.Now.Month, 15);
38+
39+
// Range compatible with DateOnly
40+
public DateOnly MonthStart { get; set; } =
41+
new DateOnly(DateTime.Now.Year, DateTime.Now.Month, 1);
42+
43+
public DateOnly MonthEnd { get; set; } =
44+
new DateOnly(
45+
DateTime.Now.Year,
46+
DateTime.Now.Month,
47+
DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month)
48+
);
49+
}
50+
```
51+
52+
Preview:
53+
- The DatePicker binds to a `DateOnly?` model, displays the value using the `yyyy-MM-dd` format, and restricts selection to the current month via `Min`/`Max`.
54+
55+
![Blazor DatePicker with DateOnly](./images/DatePickerDateOnly.gif)

0 commit comments

Comments
 (0)