You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, Is there a way to Cancel Date Range Selection when there are disabled dates in between of the date range?
So currently what I did is I disabled some dates in my calendar picker and then when I select a date range with disabled date in between, it shows that it is still a valid selection (see the attached image below, where in aug. 20 and aug 22 are the disabled dates)
So I am wondering if there is a way to cancel the range selection when there are disabled dates in between of the selected date range.
here is my code:
`val minDate = Date()
val maxDate = getDateOneYearFromToday()
val dateValidatorMin = DateValidatorPointForward.from(minDate.time)
val dateValidatorMax = DateValidatorPointBackward.before(maxDate.time)
val listValidators = mutableListOf<CalendarConstraints.DateValidator>()
listValidators.add(dateValidatorMin)
listValidators.add(dateValidatorMax)
listValidators.add(DisabledDatesValidator(listOf("2023-08-20", "2023-08-22", "2023-08-31")))
val validators = CompositeDateValidator.allOf(listValidators)
val constraintsBuilder = CalendarConstraints.Builder()
.setValidator(validators)
val dateRangePicker = MaterialDatePicker.Builder
.dateRangePicker()
.setTitleText(getString(R.string.select_date))
.setCalendarConstraints(constraintsBuilder.build())
.build()
dateRangePicker.show()`
DisabledDatesValidator.class
`class DisabledDatesValidator(private val disabledDates: List) : CalendarConstraints.DateValidator {
override fun isValid(date: Long): Boolean {
val sdf = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
val selectedDate = Calendar.getInstance()
selectedDate.timeInMillis = date
val formattedDate = sdf.format(selectedDate.time)
return !disabledDates.contains(formattedDate)
}
override fun writeToParcel(dest: Parcel, flags: Int) {
// Write any necessary parcelable data if needed
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<DisabledDatesValidator> {
override fun createFromParcel(parcel: Parcel): DisabledDatesValidator {
return DisabledDatesValidator(emptyList())
}
override fun newArray(size: Int): Array<DisabledDatesValidator?> {
return arrayOfNulls(size)
}
}
}`
The text was updated successfully, but these errors were encountered:
Hi, Is there a way to Cancel Date Range Selection when there are disabled dates in between of the date range?
So currently what I did is I disabled some dates in my calendar picker and then when I select a date range with disabled date in between, it shows that it is still a valid selection (see the attached image below, where in aug. 20 and aug 22 are the disabled dates)
So I am wondering if there is a way to cancel the range selection when there are disabled dates in between of the selected date range.
here is my code:
`val minDate = Date()
val maxDate = getDateOneYearFromToday()
DisabledDatesValidator.class
`class DisabledDatesValidator(private val disabledDates: List) : CalendarConstraints.DateValidator {
}`
The text was updated successfully, but these errors were encountered: