Skip to main content
15-Moonstone
October 20, 2020
Solved

How to disable previous dates in datepicker widget

  • October 20, 2020
  • 2 replies
  • 5421 views

I need to select dates only from September month and need to disable rest of the previous dates in date picker widget. 

Best answer by zyuan1

Only in DateTimePicker "Range" selection condition, the end date cannot be earlier than start date, will the dates in the picker be disabled and become grey.

 

And I can't find ways to compare time in Expression any more. Didn't know if I used wrong script or it's been disabled.   Time1 - Time2 = time difference (integer) used to work, and then (Time1 - Time2)>0 can be used in time comparison.

2 replies

5-Regular Member
October 20, 2020

You may not able to disable widget from selecting the time before today, but you can use a Validator Function in the mashup, to identify if the new StartDate input is earlier than the limit (trigger by Widget's Changed event), if so, a Warning message will show up;

You may also trigger a service to assign today's time to the widget if the startDate is earlier

sabharees15-MoonstoneAuthor
15-Moonstone
October 20, 2020
Hi Thanks for you suggestions,
can i get sample code for validator ??
5-Regular Member
October 20, 2020

Gave up using Expression, can't remember how to make it work.

 

I actually did this:

1. create a service in Thing, with script var result = time<new Date();  time is the input, output is boolean;

2. Add this service to mashup, add the timepicker to its input

3. create a Label widget saying "Time should not be earlier than today"

4. bind the service result to "Visible" of the Label widget, and trigger the service by timepicker "Change" event

 

Now it works

Community Manager
November 4, 2020

Hi @sabharees.

 

If you feel your question has been answered, please mark the appropriate response as the Accepted Solution for the benefit of others with the same question.

 

Regards.

 

--Sharon