material-components / material-components/material-components-android
[MaterialTimePicker] Add Input validation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 17.4k
- Forks
- 3.2k
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
Many times, apps need users to select a date+time in the past/future. `MaterialDatePicker` solves this problem by having the option to add constraints with a validator. TimePicker doesn't allow any such option.
**Describe the solution you'd like**
An `addConstraints` implementation for `MaterialTimePicker`. I understand that it won't be possible to simply extend `CalendarConstraints` for this because the time picker is only concerned with time but an option to add constraints in the form of (say) `constraintBefore(int hour, int minute)` and `constraintAfter(int hour, int minute)` can be added.
**Describe alternatives you've considered**
The present alternative to this I am using is to manually check the time from the `TimePicker` and reset the time if it doesn't fall within the required constraints. (Say I only allow time to be selected in the past, but user has entered a future time. I reset the displayed time to the current time). But this leaves room for a bad UX where the user can get confused or not even realize their selected time has been changed.
**Additional context**
An example implementation can be [this library I found on Github](https://github.com/wdullaer/MaterialDateTimePicker#timepickerdialog-setmintimetimepoint-time)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.