Class DateField
A form input control that allows users to select a date through text input or a calendar picker interface.
Inheritance
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class DateField : ExVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, IInputElement<Date>, IValidatableElement<Date>, INotifyValueChanging<Date>, INotifyValueChanged<Date>, ISizeableElement
Remarks
The DateField component combines a text input with a calendar picker to provide users with flexible date selection capabilities. Users can either type the date directly in a standardized format or click the calendar icon to visually select a date from a popup calendar interface.
The component supports different sizes to fit various layout needs and includes validation capabilities to ensure date inputs meet specific requirements.
Key features:
- Direct text input with format validation
- Calendar picker interface
- Keyboard navigation support
- Customizable date formatting
- Size variants
- Value validation
NOTE: The DateField component follows a standardized date format by default (yyyy-MM-dd) but can be customized using the formatString property.
Examples
Basic usage in UXML:
<DateField name="birthDate" />
Customized DateField with validation:
var dateField = new DateField {
formatString = "MM/dd/yyyy",
size = Size.L
};
dateField.validateValue = (date) => {
var now = Date.now;
var minAge = new Date(now.Year - 18, now.Month, now.Day);
return date <= minAge; // Validate age >= 18
};
dateField.RegisterValueChangedCallback(evt => {
Debug.Log($"Selected date: ");
});
Complete UXML example with various properties:
<DateField
name="appointmentDate"
size="M"
format-string="yyyy-MM-dd"
value="2024-01-01"
class="appointment-picker" />
Constructors
DateField()
Default constructor.
Declaration
public DateField()
Fields
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 |
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<Date, bool> validateValue { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<Date, bool> |
value
The DateField value.
Declaration
[CreateProperty]
[UxmlAttribute]
public Date value { get; set; }
Property Value
| Type | Description |
|---|---|
| Date |
Methods
SetValueWithoutNotify(Date)
Sets the DateField value without notifying the DateField.
Declaration
public void SetValueWithoutNotify(Date newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Date | newValue | The new DateField value. |