@JsModule(value="./date-picker-datefns.js") @JsModule(value="./datepickerConnector.js") @JavaScript(value="frontend://date-picker-datefns.js") @JavaScript(value="frontend://datepickerConnector.js") public class DatePicker extends GeneratedVaadinDatePicker<DatePicker,LocalDate> implements com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.data.binder.HasValidator<LocalDate>, HasClientValidation
vaadin-date-picker webcomponent.
It allows setting and getting LocalDate objects, setting minimum and
maximum date ranges and has internationalization support by using the
DatePicker.DatePickerI18n object.
| Modifier and Type | Class and Description |
|---|---|
static class |
DatePicker.DatePickerI18n
The internationalization properties for
DatePicker. |
GeneratedVaadinDatePicker.ChangeEvent<R extends GeneratedVaadinDatePicker<R,?>>, GeneratedVaadinDatePicker.InvalidChangeEvent<R extends GeneratedVaadinDatePicker<R,?>>, GeneratedVaadinDatePicker.OpenedChangeEvent<R extends GeneratedVaadinDatePicker<R,?>>com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V>HasClientValidation.ClientValidatedEventcom.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>| Constructor and Description |
|---|
DatePicker()
Default constructor.
|
DatePicker(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>> listener)
Convenience constructor to create a date picker with a
ValueChangeListener. |
DatePicker(LocalDate initialDate)
Convenience constructor to create a date picker with a pre-selected date
in current UI locale format.
|
DatePicker(LocalDate initialDate,
com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>> listener)
Convenience constructor to create a date picker with a pre-selected date
in current UI locale format and a
ValueChangeListener. |
DatePicker(LocalDate initialDate,
Locale locale)
Convenience Constructor to create a date picker with pre-selected date
and locale setup.
|
DatePicker(String label)
Convenience constructor to create a date picker with a label.
|
DatePicker(String label,
com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>> listener)
Convenience constructor to create a date picker with a
ValueChangeListener and a label. |
DatePicker(String label,
LocalDate initialDate)
Convenience constructor to create a date picker with a pre-selected date
in current UI locale format and a label.
|
DatePicker(String label,
LocalDate initialDate,
com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>> listener)
Convenience constructor to create a date picker with a pre-selected date
in current UI locale format, a
ValueChangeListener and a label. |
| Modifier and Type | Method and Description |
|---|---|
com.vaadin.flow.shared.Registration |
addInvalidChangeListener(com.vaadin.flow.component.ComponentEventListener<GeneratedVaadinDatePicker.InvalidChangeEvent<DatePicker>> listener)
Adds a listener for
invalid-changed events fired by the
webcomponent. |
com.vaadin.flow.shared.Registration |
addOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<GeneratedVaadinDatePicker.OpenedChangeEvent<DatePicker>> listener)
Adds a listener for
opened-changed events fired by the
webcomponent. |
com.vaadin.flow.shared.Registration |
addValidationStatusChangeListener(com.vaadin.flow.data.binder.ValidationStatusChangeListener<LocalDate> listener) |
protected void |
close()
Closes the datepicker overlay.
|
com.vaadin.flow.data.binder.Validator<LocalDate> |
getDefaultValidator() |
String |
getErrorMessage()
Gets the current error message from the datepicker.
|
DatePicker.DatePickerI18n |
getI18n()
Gets the internationalization object previously set for this component.
|
LocalDate |
getInitialPosition()
Get the visible date when there is no value selected.
|
String |
getLabel()
Gets the label of the datepicker.
|
Locale |
getLocale()
Gets the Locale for this date picker
|
LocalDate |
getMax()
Gets the maximum date in the date picker.
|
LocalDate |
getMin()
Gets the minimum date in the date picker.
|
String |
getName()
Gets the name of the DatePicker.
|
String |
getPlaceholder()
Gets the placeholder of the datepicker.
|
boolean |
isAutoOpen()
When auto open is enabled, the dropdown will open when the field is
clicked.
|
boolean |
isClearButtonVisible()
Gets whether this datepicker displays a clear button when it has value.
|
protected boolean |
isEnforcedFieldValidationEnabled()
Whether the full experience validation is enforced for the component.
|
boolean |
isInvalid()
Gets the validity of the datepicker output.
|
boolean |
isOpened()
Gets the states of the drop-down for the datepicker
|
boolean |
isRequired()
Determines whether the datepicker is marked as input required.
|
boolean |
isWeekNumbersVisible()
Get the state of
showWeekNumbers property of the datepicker |
protected void |
onAttach(com.vaadin.flow.component.AttachEvent attachEvent) |
void |
open()
Opens the datepicker overlay.
|
void |
setAutoOpen(boolean autoOpen)
When auto open is enabled, the dropdown will open when the field is
clicked.
|
void |
setClearButtonVisible(boolean clearButtonVisible)
Sets displaying a clear button in the datepicker when it has value.
|
void |
setErrorMessage(String errorMessage)
Description copied from corresponding location in WebComponent:
|
void |
setI18n(DatePicker.DatePickerI18n i18n)
Sets the internationalization properties for this component.
|
void |
setInitialPosition(LocalDate initialPosition)
Date which should be visible when there is no value selected.
|
void |
setInvalid(boolean invalid)
Description copied from corresponding location in WebComponent:
|
void |
setLabel(String label)
Sets the label for the datepicker.
|
void |
setLocale(Locale locale)
Set the Locale for the Date Picker.
|
void |
setMax(LocalDate max)
Sets the maximum date in the date picker.
|
void |
setMin(LocalDate min)
Sets the minimum date in the date picker.
|
void |
setName(String name)
Description copied from corresponding location in WebComponent:
|
void |
setOpened(boolean opened)
Sets the opened property of the datepicker to open or close its overlay.
|
void |
setPlaceholder(String placeholder)
Description copied from corresponding location in WebComponent:
|
void |
setRequired(boolean required)
Description copied from corresponding location in WebComponent:
|
void |
setRequiredIndicatorVisible(boolean required) |
void |
setValue(LocalDate value) |
void |
setWeekNumbersVisible(boolean weekNumbersVisible)
Set the week number visible in the DatePicker.
|
protected void |
validate()
Performs server-side validation of the current value.
|
addChangeListener, addToPrefix, checkValidity, getErrorMessageString, getI18nJsonObject, getInitialPositionString, getLabelString, getMaxAsStringString, getMinAsStringString, getNameString, getPlaceholderString, isAutofocusBoolean, isClearButtonVisibleBoolean, isDisabledBoolean, isInvalidBoolean, isOpenedBoolean, isReadonlyBoolean, isRequiredBoolean, isShowWeekNumbersBoolean, remove, removeAll, setAutofocus, setDisabled, setI18n, setInitialPosition, setMaxAsString, setMinAsString, setReadonly, setShowWeekNumbers, validategetSynchronizationRegistration, 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, waitgetCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFullgetHelperComponent, getHelperText, setHelperComponent, setHelperTextaddClientValidatedEventListeneraddClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassNameaddFocusShortcut, blur, focus, getTabIndex, setTabIndexpublic DatePicker()
public DatePicker(LocalDate initialDate)
initialDate - the pre-selected date in the pickerAbstractField.setValue(Object)public DatePicker(String label)
label - the label describing the date pickersetLabel(String)public DatePicker(String label, LocalDate initialDate)
label - the label describing the date pickerinitialDate - the pre-selected date in the pickerAbstractField.setValue(Object),
setLabel(String)public DatePicker(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>> listener)
ValueChangeListener.listener - the listener to receive value change eventsAbstractField.addValueChangeListener(HasValue.ValueChangeListener)public DatePicker(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>> listener)
ValueChangeListener and a label.label - the label describing the date pickerlistener - the listener to receive value change eventssetLabel(String),
AbstractField.addValueChangeListener(HasValue.ValueChangeListener)public DatePicker(LocalDate initialDate, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>> listener)
ValueChangeListener.initialDate - the pre-selected date in the pickerlistener - the listener to receive value change eventsAbstractField.setValue(Object),
AbstractField.addValueChangeListener(HasValue.ValueChangeListener)public DatePicker(String label, LocalDate initialDate, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>> listener)
ValueChangeListener and a label.label - the label describing the date pickerinitialDate - the pre-selected date in the pickerlistener - the listener to receive value change eventssetLabel(String),
AbstractField.setValue(Object),
AbstractField.addValueChangeListener(HasValue.ValueChangeListener)public void setMin(LocalDate min)
min - the minimum date that is allowed to be selected, or
null to remove any minimum constraintspublic LocalDate getMin()
null if there's no minimumpublic void setMax(LocalDate max)
max - the maximum date that is allowed to be selected, or
null to remove any maximum constraintspublic LocalDate getMax()
null if there's no maximumpublic void setLocale(Locale locale)
NOTE:Supported formats are MM/DD/YYYY, DD/MM/YYYY and YYYY/MM/DD. Browser compatibility can be different based on the browser and mobile devices, you can check here for more details: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleDateString
When using custom date formats through
setI18n(DatePickerI18n), setting a locale has no
effect, and dates will always be parsed and displayed using the custom
date format.
locale - the locale set to the date picker, cannot be nullpublic Locale getLocale()
getLocale in class com.vaadin.flow.component.Componentprotected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
onAttach in class com.vaadin.flow.component.Componentpublic DatePicker.DatePickerI18n getI18n()
Note: updating the object content that is gotten from this method will
not update the lang on the component if not set back using
setI18n(DatePickerI18n)
null, If the i18n
properties weren't set.public void setI18n(DatePicker.DatePickerI18n i18n)
i18n - the internationalized properties, not nullpublic void setErrorMessage(String errorMessage)
GeneratedVaadinDatePickerDescription copied from corresponding location in WebComponent:
The error message to display when the input is invalid.
setErrorMessage in interface com.vaadin.flow.component.HasValidationsetErrorMessage in class GeneratedVaadinDatePicker<DatePicker,LocalDate>errorMessage - the String value to setpublic String getErrorMessage()
getErrorMessage in interface com.vaadin.flow.component.HasValidationpublic com.vaadin.flow.data.binder.Validator<LocalDate> getDefaultValidator()
getDefaultValidator in interface com.vaadin.flow.data.binder.HasValidator<LocalDate>public com.vaadin.flow.shared.Registration addValidationStatusChangeListener(com.vaadin.flow.data.binder.ValidationStatusChangeListener<LocalDate> listener)
addValidationStatusChangeListener in interface com.vaadin.flow.data.binder.HasValidator<LocalDate>public void setInvalid(boolean invalid)
GeneratedVaadinDatePickerDescription copied from corresponding location in WebComponent:
This property is set to true when the control value invalid.
setInvalid in interface com.vaadin.flow.component.HasValidationsetInvalid in class GeneratedVaadinDatePicker<DatePicker,LocalDate>invalid - the boolean value to setpublic boolean isInvalid()
return true, if the value is invalid.
isInvalid in interface com.vaadin.flow.component.HasValidationvalidity property from the datepickerpublic void setValue(LocalDate value)
setValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>,LocalDate>setValue in class com.vaadin.flow.component.AbstractField<DatePicker,LocalDate>public void setClearButtonVisible(boolean clearButtonVisible)
The clear button is an icon, which can be clicked to set the datepicker
value to null.
setClearButtonVisible in class GeneratedVaadinDatePicker<DatePicker,LocalDate>clearButtonVisible - true to display the clear button, false to
hide itpublic boolean isClearButtonVisible()
true if this datepicker displays a clear button,
false otherwisesetClearButtonVisible(boolean)public void setLabel(String label)
setLabel in interface com.vaadin.flow.component.HasLabelsetLabel in class GeneratedVaadinDatePicker<DatePicker,LocalDate>label - value for the label property in the datepickerpublic String getLabel()
getLabel in interface com.vaadin.flow.component.HasLabellabel property of the datePickerpublic void setPlaceholder(String placeholder)
GeneratedVaadinDatePickerDescription copied from corresponding location in WebComponent:
A placeholder string in addition to the label. If this is set, the label will always float.
setPlaceholder in class GeneratedVaadinDatePicker<DatePicker,LocalDate>placeholder - the String value to setpublic String getPlaceholder()
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
placeholder property of the datePickerpublic void setInitialPosition(LocalDate initialPosition)
The same date formats as for the value property are supported.
initialPosition - the LocalDate value to setpublic LocalDate getInitialPosition()
The same date formats as for the value property are supported.
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
initialPosition property from the datepickerpublic void setRequired(boolean required)
GeneratedVaadinDatePickerDescription copied from corresponding location in WebComponent:
Set to true to mark the input as required.
setRequired in class GeneratedVaadinDatePicker<DatePicker,LocalDate>required - the boolean value to setpublic void setRequiredIndicatorVisible(boolean required)
setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>,LocalDate>setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>,LocalDate>public boolean isRequired()
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
true if the input is required, false otherwisepublic void setWeekNumbersVisible(boolean weekNumbersVisible)
Set true to display ISO-8601 week numbers in the calendar.
Notice that displaying week numbers is only supported when i18n.firstDayOfWeek is 1 (Monday).
weekNumbersVisible - the boolean value to setpublic boolean isWeekNumbersVisible()
showWeekNumbers property of the datepicker
This property is not synchronized automatically from the client side, so the returned value may not be the same as in client side.
showWeekNumbers property from the datepickerpublic void setOpened(boolean opened)
setOpened in class GeneratedVaadinDatePicker<DatePicker,LocalDate>opened - true to open the datepicker overlay, false to
close itpublic void open()
open in class GeneratedVaadinDatePicker<DatePicker,LocalDate>protected void close()
close in class GeneratedVaadinDatePicker<DatePicker,LocalDate>public boolean isOpened()
true if the drop-down is opened, false otherwisepublic void setName(String name)
GeneratedVaadinDatePickerDescription copied from corresponding location in WebComponent:
The name of this element.
setName in class GeneratedVaadinDatePicker<DatePicker,LocalDate>name - the String value to setpublic String getName()
name property from the DatePickerpublic 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 validate()
public com.vaadin.flow.shared.Registration addOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<GeneratedVaadinDatePicker.OpenedChangeEvent<DatePicker>> listener)
GeneratedVaadinDatePickeropened-changed events fired by the
webcomponent.addOpenedChangeListener in class GeneratedVaadinDatePicker<DatePicker,LocalDate>listener - the listenerRegistration for removing the event listenerpublic com.vaadin.flow.shared.Registration addInvalidChangeListener(com.vaadin.flow.component.ComponentEventListener<GeneratedVaadinDatePicker.InvalidChangeEvent<DatePicker>> listener)
GeneratedVaadinDatePickerinvalid-changed events fired by the
webcomponent.addInvalidChangeListener in class GeneratedVaadinDatePicker<DatePicker,LocalDate>listener - the listenerRegistration for removing the event listenerprotected 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 © 2024. All rights reserved.