TimePicker
in namespace DotVVM.BusinessPack.Controls
Renders a selector allowing users to select a time.
Usage & Scenarios
Renders a text field that allows the user to enter or select time.
Sample 1: Basic Usage
The SelectedTime
property represents a Time
value with a time selected in the control.
<bp:TimePicker SelectedTime="{value: SelectedTime}" />
<p>Selected time: <dot:Literal Text="{value: SelectedTime}" FormatString="g" /></p>
using System;
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.TimePicker.sample1
{
public class ViewModel : DotvvmViewModelBase
{
public DateTime SelectedTime { get; set; } = DateTime.Now;
}
}
Sample 2: Selection Bounds
You can use the MinTime
and MaxTime
properties to specify the minimum and maximum values for the selection.
<bp:TimePicker SelectedTime="{value: SelectedTime}"
MinTime="{value: MinimumTime}"
MaxTime="{value: MaximumTime}" />
<p>Selected time: <dot:Literal Text="{value: SelectedTime}" FormatString="g" /></p>
using System;
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.TimePicker.sample2
{
public class ViewModel : DotvvmViewModelBase
{
public DateTime SelectedTime { get; set; } = DateTime.Now;
public DateTime MinimumTime { get; set; } = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day,
7, 30, 0);
public DateTime MaximumTime { get; set; } = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day,
19, 30, 0);
}
}
Sample 3: Restrictions
If you require more granular control over what dates can be selected, you can use the Restrictions
property.
- TimeRangeRestriction - Allows to disable selection of a specific time range. You just need to set the
StartTime
andEndTime
properties, where theStartTime
represents inclusive start of the restriction andEndTime
represents end of the restriction. Date part of theDateTime
values is ignored so any date can be provided.
<bp:TimePicker SelectedTime="{value: SelectedTime}"
Restrictions="{value: Restrictions}" />
<p>Selected time: <dot:Literal Text="{value: SelectedTime}" FormatString="g" /></p>
using System;
using System.Collections.Generic;
using DotVVM.BusinessPack.Controls;
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.TimePicker.sample3
{
public class ViewModel : DotvvmViewModelBase
{
public DateTime SelectedTime { get; set; } = DateTime.Now;
public List<TimeRestriction> Restrictions { get; set; } = new List<TimeRestriction>()
{
//This will prevent selection of any time between 11:45:00 to 13:14:59
new TimeRangeRestriction() {
StartTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day,
11, 45, 0),
EndTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day,
13, 15, 0)
},
//This will prevent selection of any time between 16:30:00 to 17:29:59
new TimeRangeRestriction() {
StartTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day,
16, 30, 0),
EndTime = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day,
17, 30, 0)
}
};
}
}
Sample 4: Inline
The ShowInline
property toggle whether the TimePicker is displayed inline in page or as a drop-down editor.
<bp:TimePicker SelectedTime="{value: SelectedTime}"
ShowInline />
<p>Selected time: <dot:Literal Text="{value: SelectedTime}" FormatString="g" /></p>
using System;
using DotVVM.Framework.ViewModel;
namespace DotvvmWeb.Views.Docs.Controls.businesspack.TimePicker.sample4
{
public class ViewModel : DotvvmViewModelBase
{
public DateTime SelectedTime { get; set; } = DateTime.Now;
}
}
Properties
Name | Type | Description | Notes | Default Value | |
---|---|---|---|---|---|
AllowUnselect | Boolean | Gets or sets whether the selected value can be unselected. It is allowed by default. |
attribute
static value
bindable
|
True | |
AmPmDesignatorText | String | Gets or sets the text displayed above a dial used to select AM / PM designator. The default value is "AM/PM". |
attribute
static value
|
AM/PM | |
AutoFocus | Boolean | Gets or sets whether the control should have focus when page loads or when a dialog is opened. The default value is false. |
attribute
static value
|
False | |
ClientIDMode | ClientIDMode | Gets or sets the client ID generation algorithm. |
attribute
static value
|
Static | |
ConfirmIcon | IconBase | Gets or sets the icon to confirm selection and close popup dialog. |
inner element
static value
bindable
|
null | |
DataContext | Object | Gets or sets a data context for the control and its children. All value and command bindings are evaluated in context of this value. The DataContext is null in client-side templates. |
attribute
bindable
|
null | |
Enabled | Boolean | Gets or sets whether the control is enabled and can be modified. |
attribute
static value
bindable
|
True | |
FormatString | String | Gets or sets the format string that will be used to display the value. |
attribute
static value
|
null | |
HourText | String | Gets or sets the text displayed above a dial used to select hour. The default value is "Hour". |
attribute
static value
|
Hour | |
ID | String | Gets or sets the control client ID within its naming container. |
attribute
static value
bindable
|
null | |
IncludeInPage | Boolean | Gets or sets whether the control is included in the DOM of the page. |
attribute
bindable
|
True | |
MaxTime | DateTime? | Gets or sets the highest time that can be selected by user. |
attribute
bindable
|
null | |
MinTime | DateTime? | Gets or sets the lowest time that can be selected by user. |
attribute
bindable
|
null | |
MinuteText | String | Gets or sets the text displayed above a dial used to select minute. The default value is "Minute". |
attribute
static value
|
Minute | |
NextIcon | IconBase | Gets or sets the icon displayed on the button navigating to next page. |
inner element
static value
bindable
|
null | |
Placeholder | String | Gets or sets the text displayed when value is not selected. |
attribute
static value
|
null | |
PrevIcon | IconBase | Gets or sets the icon displayed on the button navigating to previous page. |
inner element
static value
bindable
|
null | |
Restrictions | IEnumerable<TimeRestriction> | Gets or sets a collection of rules specifying which time intervals can't be selected. |
attribute
bindable
|
null | |
SecondText | String | Gets or sets the text displayed above a dial used to select second. The default value is "Second". |
attribute
static value
|
Second | |
SelectedTime | DateTime? | Gets or sets the time selected by user. |
attribute
bindable
|
null | |
ShowInline | Boolean | Gets or sets whether the picker is displayed inline in page or as a drop-down editor. |
attribute
static value
|
False | |
TabIndex | Int32 | Gets or sets the order in which the control is reachable in sequential keyboard navigation. The default value is 0 which means the document order. |
attribute
static value
bindable
|
0 | |
ToggleIcon | IconBase | Gets or sets the icon displayed on the toggle button. |
inner element
static value
bindable
|
null | |
UnselectIcon | IconBase | Gets or sets the icon displayed on the unselect button. |
inner element
static value
bindable
|
null | |
UseFormatStringAsPlaceholder | Boolean | Gets or sets whether to use the FormatString as a placeholder when placeholder property is not set. It is enabled by default. |
attribute
static value
|
True | |
Visible | Boolean |
attribute
bindable
|
True |
Events
Name | Type | Description | |
---|---|---|---|
Changed | Command | Gets or sets the command triggered when the value is changed. |