vaadin / flow-components

Java counterpart of Vaadin Web Components
101 stars 65 forks source link

Provide API for setting default value for DateTimePicker.TimeField #1850

Open nSharifA opened 3 years ago

nSharifA commented 3 years ago

Use case: On some of our list windows, we have DateTime interval filter components (which is basically two DateTimePickers side by side). We use this component to filter a Grid component, which contains a LocalDateTime type column. examples.: if only (From) DateTimeField value is present: 1994.10.10 03:00, empty -> list every item which is greater than this value if only (To) DateTimeField value present: empty, 2022.10.10 04:00 -> list every item which is less than this value if both value is present: 1994.01.01 00:00, 2222.02.03 01:11 -> list every item which is in this range. if both value is empty -> no filtering

The problem: If you leave the time field empty the whole thing won't work, because the component doesn't have value until you fill the TimeField.

I tried to solve this problem this way:

  1. getValue() when query button pressed -> no value is present when only Date is picked.
  2. Look for "setDefaultTime(LocalTime time)" or "setEmptyTimeValue(LocalTime time)" methods -> no luck there, there is no API like that
  3. Listen to value change and fill the time field with a value if the user only modified the date field -> no luck there, the value change event only fires when both fields are filled. (+ it would be a hack solution) (4. Instead of DateTimePicker I could use separate DatePicker, TimePicker to look like a DateTimePicker and write my own logic to it. This should work, but i haven't tried out it yet.)

Possible solution/suggestion:

  1. Java API for setting a default empty value for the DateTimePicker.TimeField.
  2. Separate getValue() methods for DateTimePicker.DateField, DateTimePicker.DateTimeField example: getDateValue(), getTimeValue()
web-padawan commented 2 years ago

See also https://github.com/vaadin/web-components/issues/668