Aug 19, 2012, 1:53 PM
135 Posts
topic has been resolvedResolved

How to disable past dates in Date/Time picker?

  • Category: Other Domino Designer Tooling
  • Platform: Windows
  • Release: 8.5.3
  • Role: Developer
  • Tags: date picker
  • Replies: 4
 Hi,
 
is there a way to disable past dates in Date/Time picker? I've seen this in some (non Domino) applications but I haven't found a way to do this in Domino/Dojo.
 
- Panu 
Aug 20, 2012, 10:53 AM
366 Posts
Re: How to disable past dates in Date/Time picker?
 In the XPage onClientLoad event add the following code, where inputText1 is the name of the dojo date time control
 
var effectiveDate = dijit.byId("#{id:inputText1}");

var sDate = new Date();

effectiveDate.constraints.min = sDate;

Aug 21, 2012, 4:08 AM
135 Posts
Re: How to disable past dates in Date/Time picker?
Thank you Paul, this is great!
 
I noticed a couple of issues when testing this and needed to do a few changes:
 
1. dojo nor dijit seem not to be available in onClientLoad which makes this event pretty much useless
2. Then I placed the close to an scriptBlock  element at the end of the page. The control was not found by dijit.byId.
3. Finally I used dojo.ready in that scriptBlock and then it started to work
 
Here is my code in the scriptBlock:
 
dojo.ready(function() {dijit.byId("#{id:inpDate}").constraints.min = new Date();}); 
 
This might also work with attributes, something like this:
 
data-dojo-props="constraints:{min:2012-08-21}"
 
But JS is probably better since you don't have to worry about the date format.
 
EDIT: Now when I selected today my date field got surrounded by red box and an exlamation mark was shown indicating the value was not valid. This was because the time was newer than minimum time. I had to set the time to 0 to get rid of this problem:
 
var dtMin = new Date();
dtMin.setHours(0, 0, 0, 0);
dijit.byId("#{id:inpDate}").constraints.min = dtMin;
Aug 21, 2012, 10:02 AM
366 Posts
Re: How to disable past dates in Date/Time picker?
 The onclientload event has two inputs.  Client and Server.
 
Make sure you click the "Client" tab before putting the code in the script window. 
 
 
Aug 21, 2012, 10:47 AM
135 Posts
Re: How to disable past dates in Date/Time picker?
You are absolutely right! I can't believe I made that kind of mistake.
 
I never thought there would be a server side event for onClientLoad. This is very interesting, the server event runs after the client event...
 
- Panu