Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(DatePicker, TimePicker): explain constraint validation #6537

Merged
merged 34 commits into from
Sep 17, 2024
Merged
Changes from 3 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
41bec0b
docs: add brief introduction into validation
vursen Aug 12, 2024
a41a6b0
change h3 to h2
vursen Aug 13, 2024
5fbaee7
Update vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/mai…
vursen Aug 14, 2024
8a30a76
Update vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/mai…
vursen Aug 14, 2024
1eabdbc
Update vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/mai…
vursen Aug 14, 2024
8011a85
Update vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/mai…
vursen Aug 14, 2024
4cd86d5
Update vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/mai…
vursen Aug 14, 2024
8a93c9e
Update vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/mai…
vursen Aug 14, 2024
a2ef2b3
format
vursen Aug 14, 2024
b808309
add a mention of Binder
vursen Aug 14, 2024
64ad6eb
polish
vursen Aug 14, 2024
ab82b6b
format
vursen Aug 14, 2024
e470903
improve part about Binder
vursen Aug 15, 2024
fa83636
Update vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/mai…
vursen Aug 15, 2024
1232128
explain that required constraint is exception in Bindero
vursen Aug 15, 2024
7e4fa8b
polish
vursen Aug 15, 2024
36f60ce
align with text fields
vursen Aug 20, 2024
791a484
polish
vursen Aug 20, 2024
07f6127
Update vaadin-date-picker-flow-parent/vaadin-date-picker-flow/src/mai…
vursen Aug 21, 2024
857e2cb
slighly polish
vursen Aug 22, 2024
9843b90
align description
vursen Aug 22, 2024
37130e5
address code review comments
vursen Aug 26, 2024
3a8ca05
format
vursen Aug 26, 2024
b41d77f
revert unintended change
vursen Aug 26, 2024
4d319da
align with NumberField, reduce redundancy
vursen Aug 28, 2024
48dc9be
remove unnecessary JavaDoc annotations, add return annotation
vursen Aug 29, 2024
5551c58
update required docs
vursen Aug 30, 2024
d6c41a1
align with ComboBox
vursen Aug 30, 2024
ce16318
add TimePicker
vursen Sep 2, 2024
eb6b138
remove unused import
vursen Sep 2, 2024
447e78e
use 'for this field' consistently in getters and setters
vursen Sep 17, 2024
739c52c
Merge branch 'main' into improve-date-picker-validation-docs
web-padawan Sep 17, 2024
28be0ce
simplify @return annotations
vursen Sep 17, 2024
831aa4a
Merge branch 'main' into improve-date-picker-validation-docs
vursen Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@
* the format of the current locale or through the date picker overlay. The
* overlay opens when the field is clicked and/or any input is entered when the
* field is focused.
* <h2>Validation</h2>
* <p>
* DatePicker comes with a built-in validation mechanism based on constraints.
vursen marked this conversation as resolved.
Show resolved Hide resolved
* Validation is triggered when the user attempts to apply a date whether by
* entering it manually or selecting it from the overlay, or when the date is
* updated programmatically. Validation checks if the date is parsable and
* satisfies the specified constraints. If validation fails, the component is
* marked as invalid and an error message is displayed (if one is provided).
* <p>
* The following constraints can be set:
vursen marked this conversation as resolved.
Show resolved Hide resolved
* <ul>
* <li>{@link #setRequiredIndicatorVisible(boolean)}
* <li>{@link #setMin(LocalDate)}
* <li>{@link #setMax(LocalDate)}
* </ul>
* <p>
* Error messages for unparsable input and constraint violations can be
* configured using the respective methods in the {@link DatePickerI18n} object.
vursen marked this conversation as resolved.
Show resolved Hide resolved
* <p>
* In addition to validation, constraints may also have a visual representation.
* For example, dates before the minimum date appear disabled in the overlay.
* <p>
vursen marked this conversation as resolved.
Show resolved Hide resolved
* The constraint validation can be disabled by setting
* {@link #setManualValidation(boolean)} to true. This will allow the invalid
* state and the error message to be controlled manually using
* {@link #setInvalid(boolean)} and {@link #setErrorMessage(String)} API.
*
* @author Vaadin Ltd
*/
Expand Down Expand Up @@ -341,11 +367,13 @@ public DatePicker(LocalDate initialDate, Locale locale) {

/**
* Sets the minimum date in the date picker. Dates before that will be
* disabled in the popup.
* disabled in the popup. Manual entry of dates before the minimum will
* cause the component to invalidate.
*
* @param min
* the minimum date that is allowed to be selected, or
* <code>null</code> to remove any minimum constraints
* @see DatePickerI18n#setMinErrorMessage(String)
*/
public void setMin(LocalDate min) {
String minAsString = FORMATTER.apply(min);
Expand All @@ -355,7 +383,8 @@ public void setMin(LocalDate min) {

/**
* Gets the minimum date in the date picker. Dates before that will be
* disabled in the popup.
* disabled in the popup. Manual entry of dates before the minimum will
* cause the component to invalidate.
*
* @return the minimum date that is allowed to be selected, or
* <code>null</code> if there's no minimum
Expand All @@ -366,11 +395,13 @@ public LocalDate getMin() {

/**
* Sets the maximum date in the date picker. Dates after that will be
* disabled in the popup.
* disabled in the popup. Manual entry of dates after the maximum will cause
* the component to invalidate.
*
* @param max
* the maximum date that is allowed to be selected, or
* <code>null</code> to remove any maximum constraints
* @see DatePickerI18n#setMaxErrorMessage(String)
*/
public void setMax(LocalDate max) {
String maxAsString = FORMATTER.apply(max);
Expand All @@ -380,7 +411,8 @@ public void setMax(LocalDate max) {

/**
* Gets the maximum date in the date picker. Dates after that will be
* disabled in the popup.
* disabled in the popup. Manual entry of dates after the maximum will cause
* the component to invalidate.
*
* @return the maximum date that is allowed to be selected, or
* <code>null</code> if there's no maximum
Expand Down Expand Up @@ -686,22 +718,43 @@ public LocalDate getInitialPosition() {
}

/**
* Sets whether the date picker is marked as input required.
* Sets whether the user is required to provide a value. When required, a
* required indicator will be displayed next to the label, and the component
* will invalidate if the value is cleared.
* <p>
* NOTE: The required indicator won't be visible if the field doesn't have a
* label.
*
* @param required
* the boolean value to set
* true to make the field required, false otherwise
* @see #setLabel(String)
* @see DatePickerI18n#setRequiredErrorMessage(String)
*/
@Override
public void setRequiredIndicatorVisible(boolean required) {
super.setRequiredIndicatorVisible(required);
}

/**
* Gets whether the user is required to provide a value.
*/
@Override
public boolean isRequiredIndicatorVisible() {
return super.isRequiredIndicatorVisible();
}

/**
* Alias for {@link #setRequiredIndicatorVisible(boolean)}.
*
* @param required
* true to make the field required, false otherwise
*/
public void setRequired(boolean required) {
setRequiredIndicatorVisible(required);
}

/**
* Determines whether the datepicker is marked as input required.
* <p>
* This property is not synchronized automatically from the client side, so
* the returned value may not be the same as in client side.
*
* @return {@code true} if the input is required, {@code false} otherwise
* Alias for {@link #isRequiredIndicatorVisible()}
*/
public boolean isRequired() {
return isRequiredIndicatorVisible();
Expand Down