Perspective: restrict DateTime input till current date only

Hi

Is there a way to restrict the date choices in DateTime input component in perspective to not allow to select future dates, only dates till the current date should be allowed to select on the calendar and the future dates should be grayed-out/disabled.

Thanks
Yash Bhan

I put this in a change script on the value property of the DateTimePicker. It doesn’t gray out future dates, but it does disallow choosing dates in the future. You can tweak it to behave exactly how you want it to.

now = system.date.now()
	if system.date.isAfter(currentValue.value,now) and origin!='Script':
		try:
			if system.date.isAfter(previousValue.value,now):
				self.props.value = now
			else:
				self.props.value = previousValue.value
		except AttributeError:
			self.props.value = now
1 Like

Both Date Picker components have a minDate and a maxDate property to define available dates for the picker. It doesn’t truly “gray-out” the unavailable dates, but it does prevent them from being selected and it applies a “restricted” cursor when hovering over restricted dates. Months and years in the dropdown ARE grayed-out.


This feature was only introduced fairly recently (8.0.13).

2 Likes

Thanks a lot! Will try this

Ahaa, we are on 8.0.12, hence I couldn’t see the option. Thanks for the info!

1 Like

Placed a onActionPerformed event for the datepicker. add a script action with
now=system.date.now()
self.props.maxDate=now

There's no need for a script, Anders. A binding will do it with less overhead and can update constantly. In addition, your script seems to update maxDate after the user has chosen the date.

Create an Expression Binding on maxDate:
now(5000)
This will update every 5 s.