@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 HasSize, HasValidation, HasHelper, HasLabel
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,?>>
AbstractField.ComponentValueChangeEvent<C extends Component,V>
BlurNotifier.BlurEvent<C extends Component>
FocusNotifier.FocusEvent<C extends Component>
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<E extends HasValue.ValueChangeEvent<?>>
Constructor and Description |
---|
DatePicker()
Default constructor.
|
DatePicker(HasValue.ValueChangeListener<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,
HasValue.ValueChangeListener<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,
HasValue.ValueChangeListener<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,
HasValue.ValueChangeListener<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 |
---|---|
Registration |
addInvalidChangeListener(ComponentEventListener<GeneratedVaadinDatePicker.InvalidChangeEvent<DatePicker>> listener)
Adds a listener for
invalid-changed events fired by the
webcomponent. |
Registration |
addOpenedChangeListener(ComponentEventListener<GeneratedVaadinDatePicker.OpenedChangeEvent<DatePicker>> listener)
Adds a listener for
opened-changed events fired by the
webcomponent. |
protected void |
close()
Closes the datepicker overlay.
|
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.
|
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(AttachEvent attachEvent)
Called when the component is attached to a UI.
|
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)
Sets the required indicator visible or not.
|
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, validate
getSynchronizationRegistration, hasValidValue, setPresentationValue, setSynchronizedEvent
addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue, valueEquals
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCssSize, getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
getHelperComponent, getHelperText, setHelperComponent, setHelperText
getElement
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
addFocusShortcut, blur, focus, getTabIndex, setTabIndex
addBlurListener
addFocusListener
isEnabled, setEnabled
isReadOnly, isRequiredIndicatorVisible, setReadOnly
clear, getOptionalValue
addAttachListener
addDetachListener
public 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(HasValue.ValueChangeListener<AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>> listener)
ValueChangeListener
.listener
- the listener to receive value change eventsAbstractField.addValueChangeListener(HasValue.ValueChangeListener)
public DatePicker(String label, HasValue.ValueChangeListener<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, HasValue.ValueChangeListener<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, HasValue.ValueChangeListener<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()
protected void onAttach(AttachEvent attachEvent)
Component
The default implementation does nothing.
This method is invoked before the AttachEvent
is fired for the
component.
public 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 null
public void setErrorMessage(String errorMessage)
GeneratedVaadinDatePicker
Description copied from corresponding location in WebComponent:
The error message to display when the input is invalid.
setErrorMessage
in interface HasValidation
setErrorMessage
in class GeneratedVaadinDatePicker<DatePicker,LocalDate>
errorMessage
- the String value to setpublic String getErrorMessage()
getErrorMessage
in interface HasValidation
public void setInvalid(boolean invalid)
GeneratedVaadinDatePicker
Description copied from corresponding location in WebComponent:
This property is set to true when the control value invalid.
setInvalid
in interface HasValidation
setInvalid
in class GeneratedVaadinDatePicker<DatePicker,LocalDate>
invalid
- the boolean value to setpublic boolean isInvalid()
return true, if the value is invalid.
isInvalid
in interface HasValidation
validity
property from the datepickerpublic 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 HasLabel
setLabel
in class GeneratedVaadinDatePicker<DatePicker,LocalDate>
label
- value for the label
property in the datepickerpublic String getLabel()
public void setPlaceholder(String placeholder)
GeneratedVaadinDatePicker
Description 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)
GeneratedVaadinDatePicker
Description 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)
HasValue
If set visible, it is visually indicated in the user interface.
The method is intended to be used with Binder
which does
server-side validation. In case HTML element has its own (client-side)
validation it should be disabled when
setRequiredIndicatorVisible(true)
is called and re-enabled
back on setRequiredIndicatorVisible(false)
. It's
responsibility of each component implementation to follow the contract so
that the method call doesn't do anything else than show/hide the
"required" indication. Usually components provide their own
setRequired
method which should be called in case the
client-side validation is required.
setRequiredIndicatorVisible
in interface HasValue<AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>,LocalDate>
setRequiredIndicatorVisible
in interface HasValueAndElement<AbstractField.ComponentValueChangeEvent<DatePicker,LocalDate>,LocalDate>
required
- true
to make the required indicator visible,
false
if notpublic 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)
GeneratedVaadinDatePicker
Description 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 true
protected void validate()
public Registration addOpenedChangeListener(ComponentEventListener<GeneratedVaadinDatePicker.OpenedChangeEvent<DatePicker>> listener)
GeneratedVaadinDatePicker
opened-changed
events fired by the
webcomponent.addOpenedChangeListener
in class GeneratedVaadinDatePicker<DatePicker,LocalDate>
listener
- the listenerRegistration
for removing the event listenerpublic Registration addInvalidChangeListener(ComponentEventListener<GeneratedVaadinDatePicker.InvalidChangeEvent<DatePicker>> listener)
GeneratedVaadinDatePicker
invalid-changed
events fired by the
webcomponent.addInvalidChangeListener
in class GeneratedVaadinDatePicker<DatePicker,LocalDate>
listener
- the listenerRegistration
for removing the event listenerCopyright © 2023. All rights reserved.