Class DateRangeField
A form input component that allows users to select a date range with a visual calendar picker.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class DateRangeField : ExVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<DateRange>, IValidatableElement<DateRange>, INotifyValueChanging<DateRange>, INotifyValueChanged<DateRange>, ISizeableElement
Remarks
DateRangeField is a specialized input component designed for selecting a range of dates. It combines two text inputs for direct date entry with a calendar picker interface for visual date selection.
The component provides two ways to input dates:
- Direct text input: Users can type dates directly into the start and end date fields
- Calendar picker: Clicking the calendar icon opens a popover with a visual date range picker
Tip: The field supports keyboard navigation, validation, and various date formatting options to ensure proper date entry.
Examples
Basic usage in UXML — Creates a medium-sized date range field with MM/dd/yyyy format and initial date range.
<DateRangeField name="bookingDates"
size="M"
format-string="MM/dd/yyyy"
value="2023-12-25,2023-12-31" />
Complete C# example with validation and change handling — Creates a date range field that validates the selection is between 2 and 14 days and logs changes.
var dateRangeField = new DateRangeField {
size = Size.M,
formatString = "MM/dd/yyyy",
validateValue = range => {
var minStay = 2;
var maxStay = 14;
var days = (range.end - range.start).Days;
return days >= minStay && days <= maxStay;
}
};
dateRangeField.RegisterValueChangedCallback(evt => {
var range = evt.newValue;
Debug.Log($"Selected range: to ");
});
Constructors
DateRangeField()
Default constructor.
Declaration
public DateRangeField()
Fields
inputContainerUssClassName
The DateField input container styling class.
Declaration
public static readonly string inputContainerUssClassName
Field Value
| Type | Description |
|---|---|
| string |
inputUssClassName
The DateField input styling class.
Declaration
public static readonly string inputUssClassName
Field Value
| Type | Description |
|---|---|
| string |
pickerButtonUssClassName
The DateField picker button styling class.
Declaration
public static readonly string pickerButtonUssClassName
Field Value
| Type | Description |
|---|---|
| string |
separatorUssClassName
The DateField separator styling class.
Declaration
public static readonly string separatorUssClassName
Field Value
| Type | Description |
|---|---|
| string |
sizeUssClassName
The DateField size styling class.
Declaration
public static readonly string sizeUssClassName
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The DateField main styling class.
Declaration
public static readonly string ussClassName
Field Value
| Type | Description |
|---|---|
| string |
Properties
contentContainer
The content container of this DateField. This is null for DateField.
Declaration
public override VisualElement contentContainer { get; }
Property Value
| Type | Description |
|---|---|
| VisualElement |
Overrides
formatString
The DateField string formatting.
Declaration
[CreateProperty]
[UxmlAttribute]
public string formatString { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
invalid
The DateField invalid state.
Declaration
[CreateProperty]
[UxmlAttribute]
public bool invalid { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
size
The DateField size.
Declaration
[CreateProperty]
[UxmlAttribute]
public Size size { get; set; }
Property Value
| Type | Description |
|---|---|
| Size |
validateValue
The DateField validation function.
Declaration
[CreateProperty]
public Func<DateRange, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<DateRange, bool> |
value
The DateField value.
Declaration
[CreateProperty]
[UxmlAttribute]
public DateRange value { get; set; }
Property Value
| Type | Description |
|---|---|
| DateRange |
Methods
SetValueWithoutNotify(DateRange)
Sets the DateField value without notifying the DateField.
Declaration
public void SetValueWithoutNotify(DateRange newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| DateRange | newValue | The new DateField value. |