@Tag(value="vaadin-date-time-picker")
@NpmPackage(value="@vaadin/vaadin-date-time-picker",
version="2.1.0")
@JsModule(value="@vaadin/vaadin-date-time-picker/src/vaadin-date-time-picker.js")
public class DateTimePicker
extends com.vaadin.flow.component.AbstractSinglePropertyField<DateTimePicker,LocalDateTime>
implements com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.Focusable<DateTimePicker>, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.data.binder.HasValidator<LocalDateTime>, com.vaadin.flow.component.shared.HasClientValidation
vaadin-date-time-picker web component.com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V>com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>| Constructor and Description |
|---|
DateTimePicker()
Default constructor.
|
DateTimePicker(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a
ValueChangeListener. |
DateTimePicker(LocalDateTime initialDateTime)
Convenience constructor to create a date time picker with a pre-selected
date time in current UI locale format.
|
DateTimePicker(LocalDateTime initialDateTime,
com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a pre-selected
date time in current UI locale format and a
ValueChangeListener. |
DateTimePicker(LocalDateTime initialDateTime,
Locale locale)
Convenience constructor to create a date time picker with pre-selected
date time and locale setup.
|
DateTimePicker(String label)
Convenience constructor to create a date time picker with a label.
|
DateTimePicker(String label,
com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a
ValueChangeListener and a label. |
DateTimePicker(String label,
LocalDateTime initialDateTime)
Convenience constructor to create a date time picker with a pre-selected
date and time in current UI locale format and a label.
|
DateTimePicker(String label,
LocalDateTime initialDateTime,
com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
Convenience constructor to create a date time picker with a pre-selected
date and time in current UI locale format, a
ValueChangeListener
and a label. |
| Modifier and Type | Method and Description |
|---|---|
void |
addThemeName(String themeName)
Adds a theme name to this component.
|
void |
addThemeNames(String... themeNames)
Adds one or more theme names to this component.
|
com.vaadin.flow.shared.Registration |
addValidationStatusChangeListener(com.vaadin.flow.data.binder.ValidationStatusChangeListener<LocalDateTime> listener) |
DatePicker.DatePickerI18n |
getDatePickerI18n()
Gets the internationalization object previously set for this component.
|
String |
getDatePlaceholder()
Gets the placeholder string of the date field.
|
com.vaadin.flow.data.binder.Validator<LocalDateTime> |
getDefaultValidator() |
String |
getErrorMessage()
Gets the error message to display when the input is invalid.
|
String |
getLabel()
Gets the label of this field.
|
Locale |
getLocale()
Gets the Locale for this DateTimePicker
|
LocalDateTime |
getMax()
Gets the maximum date and time in the date time picker.
|
LocalDateTime |
getMin()
Gets the minimum date and time in the date time picker.
|
Duration |
getStep()
Gets the step of the time picker.
|
String |
getTimePlaceholder()
Gets the placeholder string of the time field.
|
boolean |
isAutoOpen()
When auto open is enabled, the dropdown will open when the field is
clicked.
|
protected boolean |
isEnforcedFieldValidationEnabled()
Whether the full experience validation is enforced for the component.
|
boolean |
isInvalid()
Gets the validity indication of the date time picker output.
|
boolean |
isWeekNumbersVisible()
Get the state of
showWeekNumbers property of the date picker. |
protected void |
onAttach(com.vaadin.flow.component.AttachEvent attachEvent) |
boolean |
removeThemeName(String themeName)
Removes a theme name from this component.
|
void |
removeThemeNames(String... themeNames)
Removes one or more theme names from component.
|
void |
setAutoOpen(boolean autoOpen)
When auto open is enabled, the dropdown will open when the field is
clicked.
|
void |
setDatePickerI18n(DatePicker.DatePickerI18n i18n)
Sets the internationalization properties for the date picker inside this
component.
|
void |
setDatePlaceholder(String placeholder)
Sets a placeholder string for the date field.
|
void |
setErrorMessage(String errorMessage)
Sets the error message to display when the input is invalid.
|
void |
setInvalid(boolean invalid)
Sets the validity indication of the date time picker output.
|
void |
setLabel(String label)
Sets the label for this field.
|
void |
setLocale(Locale locale)
Set the Locale for the DateTimePicker.
|
void |
setMax(LocalDateTime max)
Sets the maximum date and time in the date time picker.
|
void |
setMin(LocalDateTime min)
Sets the minimum date and time in the date time picker.
|
void |
setReadOnly(boolean readOnly) |
void |
setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
Sets whether the date time picker is marked as input required.
|
void |
setStep(Duration step)
Sets the
step property of the time picker using duration. |
void |
setThemeName(String themeName)
Sets the theme names of this component.
|
void |
setThemeName(String themeName,
boolean set)
Sets or removes the given theme name for this component.
|
void |
setTimePlaceholder(String placeholder)
Set a placeholder string for the time field.
|
void |
setValue(LocalDateTime value)
Sets the selected date and time value of the component.
|
void |
setWeekNumbersVisible(boolean weekNumbersVisible)
Show or hide the week numbers in the date picker.
|
protected void |
validate()
Performs server-side validation of the current value.
|
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEventaddValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, valueEqualsaddListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisibleclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNamegetCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullgetThemeName, getThemeNames, hasThemeNameaddFocusShortcut, blur, focus, getTabIndex, setTabIndexgetHelperComponent, getHelperText, setHelperComponent, setHelperTextaddClientValidatedEventListenerpublic DateTimePicker()
public DateTimePicker(String label)
label - the label describing the date time pickersetLabel(String)public DateTimePicker(String label, LocalDateTime initialDateTime)
label - the label describing the date time pickerinitialDateTime - the pre-selected date time in the pickersetValue(LocalDateTime),
setLabel(String)public DateTimePicker(LocalDateTime initialDateTime)
initialDateTime - the pre-selected date time in the pickerpublic DateTimePicker(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
ValueChangeListener.listener - the listener to receive value change eventsAbstractField.addValueChangeListener(HasValue.ValueChangeListener)public DateTimePicker(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
ValueChangeListener and a label.label - the label describing the date time pickerlistener - the listener to receive value change eventssetLabel(String),
AbstractField.addValueChangeListener(HasValue.ValueChangeListener)public DateTimePicker(LocalDateTime initialDateTime, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
ValueChangeListener.initialDateTime - the pre-selected date time in the pickerlistener - the listener to receive value change eventssetValue(LocalDateTime),
AbstractField.addValueChangeListener(HasValue.ValueChangeListener)public DateTimePicker(String label, LocalDateTime initialDateTime, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>> listener)
ValueChangeListener
and a label.label - the label describing the date time pickerinitialDateTime - the pre-selected date time in the pickerlistener - the listener to receive value change eventssetLabel(String),
setValue(LocalDateTime),
AbstractField.addValueChangeListener(HasValue.ValueChangeListener)public DateTimePicker(LocalDateTime initialDateTime, Locale locale)
initialDateTime - the pre-selected date time in the pickerlocale - the locale for the date time pickerpublic void setValue(LocalDateTime value)
The value will be truncated to millisecond precision, as that is the
maximum that the time picker supports. This means that
AbstractField.getValue() might return a different value than what was passed
in.
setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>setValue in class com.vaadin.flow.component.AbstractField<DateTimePicker,LocalDateTime>value - the LocalDateTime instance representing the selected date and
time, or nullpublic void setReadOnly(boolean readOnly)
setReadOnly in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>setReadOnly in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>public void setLabel(String label)
setLabel in interface com.vaadin.flow.component.HasLabellabel - the String value to setpublic String getLabel()
getLabel in interface com.vaadin.flow.component.HasLabellabel property of the date time pickerpublic void setDatePlaceholder(String placeholder)
placeholder - the String value to setpublic String getDatePlaceholder()
placeholder property of the date pickerpublic void setTimePlaceholder(String placeholder)
placeholder - the String value to setpublic String getTimePlaceholder()
placeholder property of the time pickerpublic void setStep(Duration step)
step property of the time picker using duration. It
specifies the intervals for the displayed items in the time picker
dropdown and also the displayed time format.
The set step needs to evenly divide a day or an hour and has to be larger
than 0 milliseconds. By default, the format is hh:mm (same as *
Duration.ofHours(1)
If the step is less than 60 seconds, the format will be changed to
hh:mm:ss and it can be in hh:mm:ss.fff format, when the
step is less than 1 second.
NOTE: If the step is less than 900 seconds, the dropdown is hidden.
NOTE: changing the step to a larger duration can cause a new
HasValue.ValueChangeEvent to be fired
if some parts (eg. seconds) is discarded from the value.
step - the step to set, not null and should divide a day or
an hour evenlypublic Duration getStep()
step property from the picker, unit secondspublic void setWeekNumbersVisible(boolean weekNumbersVisible)
Set true to display ISO-8601 week numbers in the calendar.
Note that displaying of week numbers is only supported when i18n.firstDayOfWeek is 1 (Monday).
weekNumbersVisible - the boolean value to set#setDatePickerI18n(DatePickerI18n),
DatePicker.DatePickerI18n.setFirstDayOfWeek(int)public boolean isWeekNumbersVisible()
showWeekNumbers property of the date picker.showWeekNumbers property from the date pickerpublic void setLocale(Locale locale)
locale - the locale to set to the DateTimePicker, cannot be nullpublic Locale getLocale()
getLocale in class com.vaadin.flow.component.Componentpublic void addThemeName(String themeName)
addThemeName in interface com.vaadin.flow.component.HasThemethemeName - the theme name to add, not nullpublic boolean removeThemeName(String themeName)
removeThemeName in interface com.vaadin.flow.component.HasThemethemeName - the theme name to remove, not nulltrue if the theme name was removed,
false if the theme list didn't contain the theme
namepublic void setThemeName(String themeName)
setThemeName in interface com.vaadin.flow.component.HasThemethemeName - a space-separated string of theme names to set, or empty
string to remove all theme namespublic void setThemeName(String themeName, boolean set)
setThemeName in interface com.vaadin.flow.component.HasThemethemeName - the theme name to set or remove, not nullset - true to set the theme name, false to
remove itpublic void addThemeNames(String... themeNames)
addThemeNames in interface com.vaadin.flow.component.HasThemethemeNames - the theme name or theme names to be added to the componentpublic void removeThemeNames(String... themeNames)
removeThemeNames in interface com.vaadin.flow.component.HasThemethemeNames - the theme name or theme names to be removed from the componentpublic void setErrorMessage(String errorMessage)
setErrorMessage in interface com.vaadin.flow.component.HasValidationpublic String getErrorMessage()
getErrorMessage in interface com.vaadin.flow.component.HasValidationpublic void setInvalid(boolean invalid)
setInvalid in interface com.vaadin.flow.component.HasValidationpublic boolean isInvalid()
isInvalid in interface com.vaadin.flow.component.HasValidationpublic com.vaadin.flow.data.binder.Validator<LocalDateTime> getDefaultValidator()
getDefaultValidator in interface com.vaadin.flow.data.binder.HasValidator<LocalDateTime>public com.vaadin.flow.shared.Registration addValidationStatusChangeListener(com.vaadin.flow.data.binder.ValidationStatusChangeListener<LocalDateTime> listener)
addValidationStatusChangeListener in interface com.vaadin.flow.data.binder.HasValidator<LocalDateTime>protected void validate()
public void setMin(LocalDateTime min)
min - the minimum date and time that is allowed to be set, or
null to remove any minimum constraintspublic LocalDateTime getMin()
null if there's no minimumpublic void setMax(LocalDateTime max)
max - the maximum date and time that is allowed to be set, or
null to remove any minimum constraintspublic LocalDateTime getMax()
null if there's no minimumpublic DatePicker.DatePickerI18n getDatePickerI18n()
DateTimePicker#setDatePickerI18n(DatePickerI18n)null, If the i18n
properties weren't set.public void setDatePickerI18n(DatePicker.DatePickerI18n i18n)
i18n - the internationalized properties, not nullpublic void setRequiredIndicatorVisible(boolean requiredIndicatorVisible)
setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DateTimePicker,LocalDateTime>,LocalDateTime>requiredIndicatorVisible - the value of the requiredIndicatorVisible to be setpublic void setAutoOpen(boolean autoOpen)
autoOpen - Value for the auto open property,public boolean isAutoOpen()
true if auto open is enabled. false otherwise.
Default is trueprotected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
onAttach in class com.vaadin.flow.component.Componentprotected boolean isEnforcedFieldValidationEnabled()
Exposed with protected visibility to support mocking
The method requires the VaadinSession instance to obtain the
application configuration properties, otherwise, the feature is
considered disabled.
true if enabled, false otherwise.Copyright © 2025. All rights reserved.