Blazor TimeInput

The Blazor Bootstrap TimeInput component is constructed using an HTML input of type 'time' which limits user input based on pre-defined parameters. This component enables users to input a time using a text box with validation or a special time picker interface.

Basic usage #

NOTE
The input UI generally varies from browser to browser. In unsupported browsers, the control degrades gracefully to type="text".

Generic type #

The Blazor Bootstrap TimeInput component supports TimeOnly and TimeOnly?. In the below example, TValue is set to TimeOnly and TimeOnly?.

Enable max min #

Set EnableMinMax="true" and set the Max and Min parameters to restrict the user input between the Min and Max range.
NOTE
If the user tries to enter a number in the TimeInput field which is out of range, then it will override with Max or Min value based on the context. If the user input exceeds the Max value, it will override with the Max value. If the user input is less than the Min value, then it will override with the Min value.

Disable #

Use the Disabled parameter to disable the TimeInput.
Entered time: 10:50 AM
Razor
<div class="mb-3">
    <TimeInput TValue="TimeOnly" @bind-Value="@time1" Disabled="@disabled" />
</div>
<div class="mb-3">Entered time: @time1</div>

<Button Color="ButtonColor.Primary" @onclick="Enable"> Enable </Button>
<Button Color="ButtonColor.Secondary" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Warning" @onclick="Toggle"> Toggle </Button>

@code {
    private TimeOnly time1 = new TimeOnly(10, 50); // 10:50 AM
    private bool disabled = true;

    private void Enable() => disabled = false;

    private void Disable() => disabled = true;

    private void Toggle() => disabled = !disabled;
}
Also, use Enable() and Disable() methods to enable and disable the TimeInput.
NOTE
Do not use both the Disabled parameter and Enable() & Disable() methods.
Entered time: 10:50 AM
Razor
<div class="mb-3">
    <TimeInput @ref="timeInput1" TValue="TimeOnly" @bind-Value="@time1" />
</div>
<div class="mb-3">Entered time: @time1</div>

<Button Color="ButtonColor.Secondary" @onclick="Disable"> Disable </Button>
<Button Color="ButtonColor.Primary" @onclick="Enable"> Enable </Button>

@code {
    private TimeInput<TimeOnly> timeInput1 = default!;

    private TimeOnly time1 = new TimeOnly(10, 50); // 10:50 AM

    private void Disable() => timeInput1.Disable();

    private void Enable() => timeInput1.Enable();
}

Validations #

Like any other blazor input component, TimeInput component supports validations. Use the DataAnnotations to validate the user input before submitting the form. In the below example, we used the Required attributes.

Events: ValueChanged #

This event fires on every user keystroke/selection that changes the TimeInput value.

Restrict the time field based on the entry in another time field #

One common scenario is that the time fields are restricted based on the entry in another time field. In the example below, we restrict the arrival time based on the selection of departure.