Blazor Input Date Only

Create input fields that let the user enter a date, either with a textbox that validates the input or a special date picker interface.

Features:

JavaScript Independence: This component operates seamlessly without requiring JavaScript, offering a lightweight and straightforward solution.

Appearance customization: Customizable styles and themes.

Rendering options: Render your component as various HTML tags for maximum flexibility and integration.

Learn about core component featuresLearn about input component features

Simple date selection:

Selected date: 01/01/0001
<BlazorLabel>
    Select a date
    <BlazorInputDateOnly @bind-Value="MyDateOnly1" />
</BlazorLabel>
<div>Selected date: @MyDateOnly1</div>

@code {
    public DateOnly MyDateOnly1 { get; set; }
}

Simple date selection with initial value:

Selected date: 02/21/2024
<BlazorLabel>
    Select a date
    <BlazorInputDateOnly @bind-Value="MyDateOnly2" />
</BlazorLabel>
<div>Selected date: @MyDateOnly2</div>

@code {
    public DateOnly MyDateOnly2 { get; set; } = DateOnly.FromDateTime(DateTime.Now);
}

Date selection with Min, Max and Step:

Selected date: 02/21/2024
<BlazorLabel>
    Select a date
    <BlazorInputDateOnly @bind-Value="MyDateOnly2" Min="MinDate" Max="MaxDate" Step="3" />
</BlazorLabel>
<div>Selected date: @MyDateOnly2</div>

@code {
    public DateOnly MyDateOnly2 { get; set; } = DateOnly.FromDateTime(DateTime.Now);
    public DateOnly MinDate { get; set; } = DateOnly.FromDateTime(DateTime.Now.AddDays(-10));
    public DateOnly MaxDate { get; set; } = DateOnly.FromDateTime(DateTime.Now.AddDays(10));
}

Disabled input:

<BlazorLabel>
    Select a date
    <BlazorInputDateOnly @bind-Value="..." @bind-disabled="Disabled" />
</BlazorLabel>
<BlazorButton type="button" @onclick="_ => Disabled = !Disabled" Variants="Disabled?new[] {BaseVariants.Success}:new[] {BaseVariants.Danger}">@(Disabled ? "Enable" : "Disable")</BlazorButton>

@code {
    public bool Disabled { get; set; } = true;
}

Appearance Customization

Learn about Theme Feature
Component & Variants CSS class
BlazorFormControl form-control
BlazorFormControl.invalid border-danger
BlazorFormControl.valid border-success

Parameters

BlazorInputDateOnly

Name Type Description
RenderAs string Specifies the HTML tag to be used for rendering the component. This can be any valid HTML tag, such as div, span, button, or other suitable tags.
Variants string[] Specifies the variant of the component.
Value DateOnly The value of the input.
UpdateOnHtmlEvent string This parameter allows you to specify which HTML event should trigger a re-render or update of the component. When the specified event occurs on the input element, the component will initiate the parsing process, updating its internal value to reflect the UI input. Default event is onchange.
ValueParsed EventCallback<ParseEventArgs> Specify an action or method to be executed when the component parses a value, whether the parsing operation succeeds or fails.
FieldState FieldState Represents the state of a field or input element within the component. Can be used to track and manage the state of the field and display relevant messages to the user.
ParseValueHandler Func<string?, TValue?> Implement specialized parsing logic for the component, such as handling user input, converting strings to specific data types, which corresponds to the type of the Value parameter in the component and performing validation during the parsing process.
Max DateOnly Ensures that users cannot select a date beyond the specified maximum date value using the UI. If the underlying value is changed programmatically or by another UI input control, it's essential to note that the value assigned may potentially exceed the maximum date limit.
Min DateOnly Ensures that users cannot select a date beyond the specified minimum date value using the UI. If the underlying value is changed programmatically or by another UI input control, it's essential to note that the value assigned may potentially exceed the minimum date limit.
Step int Determines the incremental changes in the date value. For example, if Step is set to 7, each interaction will result in a one-week change in the date.
An error has occurred. This application may no longer respond until reloaded. Reload 🗙